Batch file to delete specific files on multiple folders
Posted: 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.
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.
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"
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.