开发者

nested forfiles: path and extension filter

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]


Instead of forfiles you can use two nested FOR commands.

see the following one-liner example to test in a 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 to include in a BAT file

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


FORFILES seems to be able to recognise \" as the way of escaping inner ". So, the following should work:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜