is there any possibility to nest two forfile
commands so that I can filter by pathname and by extension and then run a command only on those double filtered files?
By example I'd like to get all Outlook HTML-signatures of all users. I can do this by
forfiles /s /p c:\Users /m *Signatures* /c "cmd /c forfiles /s /p @path /m *.htm"
But this will only display the filenames because it's the default behavior of forfiles
to call cmd /c echo @file
.
Changing this doesn't work because then I'd need to set the /c
-option in the inner forfiles
command which requires to set the command in quotes resulting in double quotes:
forfiles /s /p c:\Users /m *Signatures* /c "cmd /c forfiles /s /p @path /m *.htm /c "cmd /c echo @path""
How can I escape the inner quotes or use some different approach to run any command on all files filtered by a substring of path and the file extension?
Kind regards
sc911
[edit] forgot /s
for recursive searching [/edit]
FORFILES
seems to be able to recognise\"
as the way of escaping inner"
. So, the following should work:Instead of
forfiles
you can use two nestedFOR
commands.see the following one-liner example to test in a cmd prompt
and use this code as a skeleton to include in a BAT file