File Attachments: Path and Extension Filter

is it possible to attach two forfile commands forfile that I can filter by path and extension , and then run the command only for these files with a double filter?

As an example, I would like to get all the Outlook HTML signatures of all users. I can do it with

 forfiles /s /pc:\Users /m *Signatures* /c "cmd /c forfiles /s /p @path /m *.htm" 

But this will only display file names, because this default forfiles causes cmd /c echo @file .

Changing this does not work, because then I will need to install /c -option in the internal forfiles command, for which I need to install the command in quotes, which leads to double quotes:

 forfiles /s /pc:\Users /m *Signatures* /c "cmd /c forfiles /s /p @path /m *.htm /c "cmd /c echo @path"" 

How can I escape the internal quotes or use some other approach to run any command for all files filtered by a substring of the path and file extension?

Regards, sc911

[edit] forgot /s for recursive search [/ edit]

+4
source share
2 answers

FORFILES seems to be able to recognize \" as a way to avoid internal. " So the following should work:

 forfiles /pc:\Users /m *Signatures* /c "cmd /c forfiles /p @path /m *.htm /c \"cmd /c echo @path\"" 
+2
source

Instead of forfiles you can use two nested FOR commands.

see the following single-layer example for verification at the cmd prompt

 @for /d %d in (c:\Users\*signature*) do @for %f in (%d\*.htm) do @echo %f 

and use this code as a skeleton for inclusion in a BAT file

 for /d %%d in (c:\Users\*signatures*) do ( for %%f in (%%d\*.htm) do ( echo %%f ) ) 
+7
source

All Articles