I have a directory as such:
D:\Movies
D:\Movies\MovieTitle1\backdrops\
D:\Movies\MovieTitle2\backdrops\
D:\Movies\MovieTitle3\backdrops\
D:\Movies\MovieTitle4\backdrops\
How could I have a batch file delete all folders named "Backdrops"? I would prefer it to run recursive from just the D:\ drive if possible.
Short answer:
Cd into the parent directory you want to navigate, e.g. cd C:\
.
To recursively delete all subdirectories named backdrops
, run
FOR /d /r . %d IN (backdrops) DO @IF EXIST "%d" rd /S /Q "%d"
Remove the /Q
option if you want to confirm each deletion.
If you put this commands in a batch file, you need to escape %d
as %%d
.
I got my answer from one of the countless answers to the same question on Stack Overflow:
Command line tool to delete folder with a specified name recursively in Windows?
This command is not tested, but I do trust this site enough to post this answer.