for /f "delims=*" %f in ('dir "C:\folder\of\files\*.efs" /b') DO C:\folder\of\executable\program.exe -f "C:%~pf%f"
- A standard debugging technique is to insert the
echocommand into scripts and even compound/complex commands. If you do
for /f "delims=*" %a in ('dir *.avi /b /s') do @echo md "%~na"
you’ll get the output
"file 1" "file 2" "file 3" "file 4"
echocommands themselves from displaying, so you see only their output.
forhow to parse the lines of output from the
dir *.avi /b /scommand. I don’t know why the answer you linked to suggests
"delims=*". But the default behavior is to break lines apart at spaces, so, if your directory and/or file names contain spaces (as you indicated), you should use
"delims="(specifying that there are no delimiters) to get this to work.
- If you type
help for, you’ll get documentation on the
forcommand. Down in the fifth page, you’ll see
In addition, substitution of FOR variable references has been enhanced. You can now use the following optional syntax: %~I - expands %I removing any surrounding quotes (") ︙ %~pI - expands %I to a path only %~nI - expands %I to a file name only ︙ The modifiers can be combined to get compound results … ︙
which explains why
%~nais getting you just the file name of the
*.avifiles whose full names are in
%a. Now try
for /f "delims=" %a in ('dir *.avi /b /s') do @echo md "%~pa"
and you’ll get
"the_current_directory\Folder A\" "the_current_directory\Folder A\" "the_current_directory\Folder B\" "the_current_directory\Folder B\"
From which we can conclude that you want to do
for /f "delims=" %a in ('dir *.avi /b /s') do md "%~pa%~na"
to create the
file 2directories under
Folder A, and the
file 4directories under
Folder B. And, as @dave_thompson_085 points out, you can combine