id="info"

Question

Locked

MS-DOS code to delete old Files

By 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.

This conversation is currently closed to new comments.

8 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

my suggestion

by jck In reply to MS-DOS code to delete old ...

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

Collapse -

Perhaps this will get you started

by Kenone In reply to MS-DOS code to delete old ...

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.

Collapse -

Forfiles command is not recognized

by jutpro In reply to Perhaps this will get you ...

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.

Collapse -

It's a server command

by Kenone In reply to Forfiles command is not r ...

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

Collapse -

Apparently this is the equivalent

by Kenone In reply to Forfiles command is not r ...

http://winhlp.com/node/386

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

Collapse -

You can also

by Kenone In reply to Forfiles command is not r ...

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.

Collapse -

You have been very helpful

by jutpro In reply to You can also

Thank you Kenone. I appreciate all your help.

Back to Windows Forum
8 total posts (Page 1 of 1)  

Operating Systems Forums