Reputation: 33
I want to delete folders within a folder by identifying the folders with specific patter that I'm looking for. ..for example if there are 6 folder as below, i want to delete folders with pattern that has string "-dated" as part of folder name ... can some one help me how I can do this in a batch file
1 . "target-dated-29sep"
2 . "target-dated-28sep"
3 . "target"
4 . "target-dated-27sep"*
5 . "BIN"
Upvotes: 3
Views: 3484
Reputation: 22211
You can use the FOR /D %variable IN (set) DO command [command-parameters]
with a pattern in the set part of the command like so:
FOR /d %%a in (\*dated\*) DO RD /s /q "%%a"
NOTES:
%
needs to be escaped inside the batch file, whereas directly in the command line you would only need a single %
sign.for /?
and rd /?
Upvotes: 6