I am trying to delete directories older than one month from a batch file. I am able to list directory names using:
dir D:* /A:D-H
But not sure how can I delete them for a specific time.
Can somebody help me with this?
I am trying to delete directories older than one month from a batch file. I am able to list directory names using:
dir D:* /A:D-H
But not sure how can I delete them for a specific time.
Can somebody help me with this?
Use forfiles
command.
Syntax:
FORFILES [/p Path] [/m Mask] [/s] [/c Command] [/d [+ | -] {dd/MM/yyyy | dd}]
The following command
forfiles /p "C:\source_folder" /s /m *.* /c "cmd /c Del @path" /d -30
will erase files in c:\source_folder
older than 30 days.
See more examples and explications here
SET FOLDERPATH="F:\TestEnvir\bin\backup\MarketData\D" rem FORFILES /p %FOLDERPATH% /S /D 30 /C "cmd /c IF @isdir == TRUE rd /S /Q @path"