简体   繁体   中英

Windows Batch "dir" command change?

It seems unlikely, but I can only assume that something changed recently (this week) during a Windows Update.

At least two scripts that use to work now do not. That is, scripts I use almost every day. Among them are my script builder for a small Java project.

dir /s /B /a:-d *.java >sources.txt

"%JAVA_HOME%"\bin\javac %javaopts% -d ..\classes -nowarn -classpath %clspath% @sources.txt

Standard, right? Except "dir" no longer removes the directory name (per a:-d) as it used to. Hence, my java compile script is failing. (Why yes, I also use Eclipse.)

As in, the files listed in the sources contain the full path of the file ("C:\\X\\Y\\Z\\src\\foo.java"). By manually remove the path preceding src ("c:\\x\\y\\z") the same script works. I've tried different case on the options, changing around the javac command, but I always get the parsing error "unknown option c:...:) because of the full paths identified in the sources file.

Regardless of why it happened, it's happening now and I am looking for an alternative which I haven't found yet. A simple alternative - I probably could write a loop that removes anything before "src" (for example) - but these two commands are cited many, many places so I thought I'd save someone the time and post myself.

The folks who commented are correct. the argument /a:-D does not remove directories. See dir .

When you think abut it, if you want to "build a small Java project" (using the 2nd line of your script), why would you want to delete the folders that contain the java files whose fully qualified file names are written to sources.txt ?

/s: Lists every occurrence of the specified file name within the specified directory and all subdirectories.

/b: Displays a bare list of directories and files (fully qualified names), with no additional information (ie, date, time, size are omitted).

/a[[:]]: Displays only the names of those directories and files with the attributes that you specify.

If you use /a specifying the -d attribute, Directories ( d means Directories ) are Not displayed ( - means Not )

The bottom line is that sources.txt will have a bare list of fully qualified file names matching the mask *.java at and below whatever the current directory is at the time you run your script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM