what is the CMD command to delete the files which is two days older from a particular folder when we run a batch file?
2 Answers
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.
Comments
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?
2 Comments
Guillaume Lafrance
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
dbenham
Easier said than done. It can be done, but your answer does not explain how.