Page 1 of 1

Batch file to delete specific files on multiple folders

Posted: 07 Feb 2022 14:43
by a3dview
I need to delete specific files from 28 folders on the same server.

e.g
C:/folder/DMP/app_x1
C:/folder/DMP/app_x2
C:/folder/DMP/app_x3
C:/folder/DMP/app_x4
C:/folder/DMP/app_x5
C:/folder/DMP/app_x6

DeleteList.txt has a list of files names (with path) need to delete from each above folders.

C:/folder/DMP/app_x0/ABC1.txt
C:/folder/DMP/app_x0/ABC1.doc

The batch file needs to have a loop to go through each folder one by one and delete all files mentioned in a text file. Following worked ok for one folder only if I specify the full path before each file's names in DeleteList.txt file.

Code: Select all

for /f "delims=" %%f in (DeleteList.txt) do del "%%f"
How to use above so that same code could run 28 times in batch file but each time replaces folder location path.
DeleteList.txt will not change. So listed files in this text file need to delete from all specified folders.

Any sample code/suggestion would help. Thx.

Re: Batch file to delete specific files on multiple folders

Posted: 07 Feb 2022 21:48
by Squashman
Like your question over on StackOverFlow , I find your technical requirements vague and incomplete. You need to be very specific and provide accurate details of everything.

Re: Batch file to delete specific files on multiple folders

Posted: 08 Feb 2022 04:43
by Compo
As an alternative to the solution you've been provided with already, over on StackOverflow, maybe the following would work for you.

Code: Select all

@For /F "UseBackQ Delims=" %%G In ("DeleteList.txt") Do @For /D %%H In ("C:\folder\DMP\app_x*") Do @Del /A /F "%%~H\%%~nxG"