bat function to find a file in folder and subfolders and do something with it.

Davinel picture Davinel · Feb 4, 2012 · Viewed 21.9k times · Source

I need to find all files with specific filename(for example main.css) in folder and all subfolders and then do something with it(eg. rename, move, delete, add text line, etc)

Answer

David Heffernan picture David Heffernan · Feb 4, 2012

This is what you need:

for /R %f in (main.css) do @echo "%f"

Naturally you would replace echo with whatever it is you wish to do to the file. You can use wildcards if you need to:

for /R %f in (*.css) do @echo "%f"