Delete file name from subfolders

I am trying to use a batch file to delete all files with a given name in all subdirectories under a subdirectory. I basically have a folder with thousands of folders with GUID names that have a file that needs to be removed from each of them regularly, and I don’t want to continue searching and deleting.

typical subfolders are as follows:

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 remove:

 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 still have .. 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. Just answer how to do this in a batch file =)

+4
source share
3 answers

safety loops with a safe belt:

 for /d /r "C:\folder" %%i in (*) do if exist "%%~fi\log.xml" echo del "%%~fi\log.xml" 
+3
source

* CHECK THIS ON THE FIRST TEST TEST - VERY VERY DANGEROUS IF YOUR TIPING IS BAD AS MY

(Sorry to scream - but you need to be very, very careful with this ...

Try this command FIRST

 DIR /S c:\FOLDER\log.xml 

and if this creates a list of files that you want to delete,

 DEL /S c:\FOLDER\log.xml 

will delete them.

+3
source
 for /f %%i in ('dir {*} /s /b') do cd %%i&&del log.xml 

for use on the command line just replace %% i with% i. this should remove log.xml from any folder names, starting with '{' and ending with '}'

First go to the desired directory!

+1
source

Source: https://habr.com/ru/post/1488347/


All Articles