Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete filename from subfolders

I am trying to use a batch file to delete all files of a given name in all sub directories under a sub directory. I basically have a folder that has thousands of folders with GUID names that has a file that needs to be deleted out of each one regularly and I don't want to keep having to do a search and delete.

typical subfolders look like:

C:\folder\{000D5D3E-A54D-4B0B-8B03-95AC591CB20A}\
C:\folder\{00DBFD07-3218-4DC2-83CA-27A7D14D782C}\
C:\folder\{00A08715-0811-6142-50AE-82A332EA3A5F}\
...etc

and I want to delete:

C:\folder\{000D5D3E-A54D-4B0B-8B03-95AC591CB20A}\log.xml
C:\folder\{90DBFD07-3218-4DC2-83CA-27A7D14D782C}\log.xml
C:\folder\{A0A08715-0811-6142-50AE-82A332EA3A5F}\log.xml
...etc

This is what I have so far.. but I can't get it to work.. any suggestions?

SET _DIR_="C:\FOLDER"
SET _PATTERN_="C:\folder\{*}\log.xml"
C:
CD %_DIR_%
for /r /%f in (%_PATTERN_%) do ECHO "%f"

Thanks. Please only reply with ways to do this in a batch file =)

like image 202
Dave Avatar asked Feb 17 '23 02:02

Dave


2 Answers

love loops with safe belt:

for /d /r "C:\folder" %%i in (*) do if exist "%%~fi\log.xml" echo del "%%~fi\log.xml"
like image 88
Endoro Avatar answered Feb 23 '23 14:02

Endoro


*TEST THIS ON A TEST SUBTREE FIRST - IT'S VERY DANGEROUS IF YOUR TYPING IS AS BAD AS MINE

(Sorry to shout - but you do need to be very, very careful with this one...

Try this command FIRST

DIR /S c:\FOLDER\log.xml

and if that produces a list of the files you want to delete, then

DEL /S c:\FOLDER\log.xml

will delete them.

like image 28
Magoo Avatar answered Feb 23 '23 13:02

Magoo