For another task I am searching for a way to iterate over all files with the extensions
*.pdf
*.doc
*.txt
in a certain directory tree with e.g. the top node
D:\sample\foo\bar\
The files should be taken in alphabetical sort order (including the path name).
Within the loop some tasks should be applied for each (current) file.
How can I achieve this?
Thank you
Peter
Iterate over all files in dir tree in alphabetical sort orde
Moderator: DosItHelp
Re: Iterate over all files in dir tree in alphabetical sort
Try this and see if the output is what you need, to begin with.
Code: Select all
dir "D:\sample\foo\bar\*.pdf" "D:\sample\foo\bar\*.doc" "D:\sample\foo\bar\*.txt" /b /a-d |sort >tempfilelist.txt
Re: Iterate over all files in dir tree in alphabetical sort
The DIR output should be in alphabetic sequence by default.
Code: Select all
@PUSHD D:\SAMPLE\FOO\BAR
@DIR/B/S/AD *.DOC *.PDF *.TXT
Re: Iterate over all files in dir tree in alphabetical sort
Thank you.
But I need a loop where each file is selected at a time.
For simplicity the file should be output by just an echo command.
How can I put the suggested dir cmds into a loop?
But I need a loop where each file is selected at a time.
For simplicity the file should be output by just an echo command.
How can I put the suggested dir cmds into a loop?
Re: Iterate over all files in dir tree in alphabetical sort
Here you go:
Code: Select all
@PushD D:\Sample\Foo\Bar
@For /f "tokens=*" %%A In ('DIR/B/S/A-D *.DOC *.PDF *.TXT') Do @(
Echo=%%A&&TimeOut /t 1 >Nul)