Questions

MS-DOS code to delete old Files

+
0 Votes
Locked

MS-DOS code to delete old Files

jutpro
I am using windows XP and need to write a DOS batch (.bat) file that will delete old files from a directory. This will run on a schedule and will not require human interaction to input any data. My problem is, I am not good at writing batch files. I can do the basic 101 type stuff, but finding dates and doing date comparison is beyond me.

This batch file will need to check the current date and then compare this date with the file date. If a file is found to be greater than, say, 3 months old then delete that file, then go to the next file and repeat the process until the end of file is reached.

Is anyone out there good with writing DOS batch files and can give me some help on this? If you can also recommend a good free online site where I can go to understand the syntax of finding the file date and how to compare dates? I have found several tutorials but they do not touch on dates. Thanks.
+
0 Votes
jck
Collapse -

write a batch that uses xcopy to copy files by date into a temp folder, then delete the temp folder.

+
0 Votes
Kenone
Collapse -

forfiles /p d:\Foldername /s /m *.* /d -10 /c "cmd /c del @file : date >= 90 days"

You could run it as a scheduled task.
Try it out on a tmp folder with unnecessary files first.

+
0 Votes
jutpro
Collapse -

Hi Kenone, thank you for your response.

I ran the batch file at the DOS prompt and the "forfiles" command is not recognized. I received the below error message;


'forfiles' is not recognized as an internal or external command,operable program or batch file.

+
0 Votes
Kenone
Collapse -

I run it from a server to clean out FTP files every night.

+
0 Votes
Kenone
Collapse -

http://winhlp.com/node/386

It's called delold and replaces forfiles on workstations. I've never used it so be careful.

+
0 Votes
Kenone
Collapse -

download and copy forfiles.exe into the system32 folder and it works with XP SP3.
I did that so long ago that I forgot that I had done it.

+
0 Votes
jutpro
Collapse -

Thank you Kenone. I appreciate all your help.