Answer the question
In order to leave comments, you need to log in
How can I achieve the same result with for as with the dir command?
There is a perfectly working command dir /s /b
Displays folders and all files in the folder as a full path.
C:\myfolder\1\1.JPG
C:\myfolder\1\2.JPG
C:\myfolder\1\3.JPG
C:\myfolder\2\1.JPG
C:\myfolder\2\2.JPG
C:\myfolder\2\3.JPG
Answer the question
In order to leave comments, you need to log in
I would suggest stuffing dir into for /f
and into for to process the output of dir, adding the necessary information:
for /f "tokens=* delims" %%a in ('dir /s /b *') in (
rem Тут можно писать любой другой код. Имя текущего файла в %%a
echo %%~a
)
Help tried to read for /?
:
Lists folders and all files in a folder as a full path.
for
with the key /r
. If subdirectories are needed, use the /d /r
. In one list without intercepting the output of the command dir
, most likely it is impossible.
Guys, I warn against using multiline constructions in brackets
for /f "tokens=* delims" %%a in ('dir /s /b *') in (
there are many many lines
)
I got a number of glitches when using such a construction. At some point, the script completely broke down if you add an empty line inside ( ) or comment out one of those present.
Rewrote everything to subroutines and glitches are gone.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question