what is the CMD command to delete the files which is two days older from a particular folder when we run a batch file?
Asked
Active
Viewed 526 times
2 Answers
1
You could use FORFILES command together with DEL: FORFILES has an option to filter files older than x days and than execute another command on filtered files.
forfiles /P "path you want to search files" /S /D -2 /C "cmd /c del @file"
FORFILES is a native command under Vista/Windows7/2008, you can get it from the Resource Kit for Windows XP. Note that the syntax may change a little depending on version of FORFILES you're using.

Luca Clavarino
- 404
- 1
- 4
- 16
0
You could use the fileDate variable, and compare it to the current date, then if it is 2 days or older, you run the eraser over it?

Guillaume Lafrance
- 69
- 2
- 5
-
Let's say you test a file named "Bacon.egg". You use the fileDate variable, check if it's old enough, then use the DEL command : DEL bacon.egg – Guillaume Lafrance Aug 14 '13 at 09:50
-
Easier said than done. It can be done, but your answer does not explain how. – dbenham Aug 14 '13 at 15:12