I will open a different answer, because it would be too cramped in the comments. It was asked what to do, if you want to execute from/to a different folder and I want to give an example for non-recursive deletion.
First of all, when you use the command in cmd, you have to use %d
, but when you use it in a .bat, you have to use %%d
.
You can use a wildcard to just process folders that for example start with "backdrops": "backdrops*"
.
Recursive deletion of folders starting in the folder the .bat is in:
FOR /d /r . %d IN ("backdrops") DO @IF EXIST "%d" rd /s /q "%d"
Non-recursive deletion of folders in the folder the .bat is in (used with wildcard, as you cannot have more than one folder with the same name anyway):
FOR /d %d IN ("backdrops*") DO @IF EXIST "%d" rd /s /q "%d"
Recursive deletion of folders starting in the folder of your choice:
FOR /d /r "PATH_TO_FOLDER" %d IN ("backdrops") DO @IF EXIST "%d" rd /s /q "%d"
Non-recursive deletion of folders in the folder of your choice (used with wildcard, as you cannot have more than one folder with the same name anyway):
FOR /d %d IN ("PATH_TO_FOLDER/backdrops*") DO @IF EXIST "%d" rd /s /q "%d"
D:\
if you want this to run onD:\
or add acd /d D:\
before thefor /d /r
loop – Intermarriage