Friday, January 30, 2015

Delete folder recursively using Regex in DOS

Below is a little script code I regularly use to delete folders with data that is no longer required.Ideally this could be automated into a batch script and scheduled to run using task scheduler on a monthly/yearly basis to avoid manual maintenance.

For example: I want to delete all folders/subfolders if any,  that starts with the year 2013.

for /d %a in (D:\MainFolder\Data\2013*) do rmdir %a /q /s

Note: If you use rd instead of rmdir you will get a message that the directory is not empty.





No comments: