I often see, and use, examples of For loops like this:
Code: Select all
For %A In (*.doc) Do @Echo %A
Code: Select all
For /F "Delims=" %A In ('Dir /B/A-D *.doc') Do @Echo %A
Code: Select all
C:\Users\Compo>For %A In (Desktop\test\*.doc) Do @Echo %~nxA
FileName01.docm
FileName03.docx
FileName01.doc
FileName02.doc
FileName01.docx
FileName02.docx
Code: Select all
For /F "Delims=" %A In ('Dir /B/A-D "Desktop\test\*.doc" 2^>Nul') Do @Echo %A
FileName01.docm
FileName03.docx
FileName01.doc
FileName02.doc
FileName01.docx
FileName02.docx
I know the Where command is successful:
Code: Select all
C:\Users\Compo>For /F "Delims=" %A In ('Where "Desktop\test":*.doc 2^>Nul') Do @Echo %~nxA
FileName01.doc
FileName02.doc
- Is there a simpler or better recommended pre-processing method of matching only the extension entered?
(I'm aware that there are post-processing methods, e.g. piping the output through FindStr or using If %~xA==.doc etc.) - Why does nobody ever seem to complain that *.doc is matching extensions they didn't ask for?