How do I create a batch file that deletes files from multiple directories?
D:\L1\asdasda\L3\*.txt
D:\L1\dfghfghfh\L3\*.txt
D:\L1\tyutyugj\L3\*.txt
D:\L1\ytrtyrty\L3\*.txt
Like:
D:
del "d:\L1\*\L3\*.txt"
Note by barlop- questioner adds-
I have about a hundred of those directories. I do not want to delete the Folders, only the files. All of them have a L3 Folder, and they all contain some files with the same extension. Those are just temporary files, but it does not delete automatically.
Best Answer
BATCH FILE TO DELETE FROM SUBFOLDERS WITH DIFFERENT NAMES DYNAMICALLY USING WILDCARD FOR SUBFOLDER NAMES
Here's an easy and simple batch script example that I use to complete this type of task all the time, I plugged in the variable folder paths to suit your needs as you describe:
SAMPLE BATCH SCRIPT
(Set your variable root folder and subfolder up top, and the
FOR /D
andFOR
loops iterate accordingly to do the rest of the magic traversing the directory as the logic specifies and completes theDEL /Q /F
command for the*.txt
files)NOTE: If you plan to run this with a copy and paste manually in the command prompt, then the variables in the
FOR
loops need to have one of the percent signs removed in all parts so use the below for that part if you're running this manually with a copy and paste rather than in a batch script and executing that which is how the above example will work.FURTHER DETAIL AND RESEACH
(Type in
FOR /?
in Windows Command Prompt to see this detail)FOR (with no switch)
FOR /D