Batch file to delete specific files on multiple folders

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
a3dview
Posts: 1
Joined: 07 Feb 2022 14:37

Batch file to delete specific files on multiple folders

#1 Post by a3dview » 07 Feb 2022 14:43

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.

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Batch file to delete specific files on multiple folders

#2 Post by Squashman » 07 Feb 2022 21:48

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.

Compo
Posts: 599
Joined: 21 Mar 2014 08:50

Re: Batch file to delete specific files on multiple folders

#3 Post by Compo » 08 Feb 2022 04:43

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"

Post Reply