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
echo
command into scripts and even compound/complex commands. If you dofor /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"
Notes:
- The
@
prevents theecho
commands themselves from displaying, so you see only their output. "delims=…"
tellsfor
how to parse the lines of output from thedir *.avi /b /s
command. 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.
- The
- If you type
for /?
orhelp for
, you’ll get documentation on thefor
command. Down in the fifth page, you’ll seeIn 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
%~na
is getting you just the file name of the*.avi
files whose full names are in%a
. Now tryfor /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 1
andfile 2
directories underFolder A
, and thefile 3
andfile 4
directories underFolder B
. And, as @dave_thompson_085 points out, you can combine%~pa%~na
into%~pna
.
https://superuser.com/questions/1033360/how-do-i-execute-commands-on-files-in-multiple-folders