I need help with a batch script that will delete 30 days old files from a folder automatically. I have read about forfiles and I am doing something wrong. I don't know where the file goes when I click on forfiles.exe. Anyways, if someone can help me with this, I would greatly appreciated it. Also, I have to setup a separate batch script that would delete folders older than 7 days and their subfolders and files. Thank you!

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

Processing your response...

Discuss This Question: 12 &nbspReplies

There was an error processing your information. Please try again later.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

thanks for the links ... the batch file is couple of pages of code ... i am looking for something that can be put together in few lines and delete the files ... Microsoft have something called ForFiles and if i can only figure it out how that works ... it would save me tons of time ... if you can recommend something else, great, if not, no biggy ... thanks

I have use the script that you suggested ... getting an error ... attach is the script i ran and the error i get ... i am testing a folder that has 90 files and i want to delete files that are 30 days old
Thanks for any of your help with this

In the screen shot you sent, I can see that the double quotes are not showing properly, and thus the second /c, which is in fact part of the command you want to execute to the files, is being taken as a second /c option for the forfiles command.
Did you copy and paste the script text ?
If so, try again, but write the script manually.

I tested your script, and it worked for me.
The error message you are getting is not really an error, but a message saying that no files older than 30 days exists in the 'c:test072909' directory.
By the way, I would test changing the "cmd /c del @file" command to "cmd /c echo @file", which would list the files being affected. When you have it working, you can change the command to delete the files again.

Also, i want to know if there is a way to delete Folder (for example Mon_07-01-2009, Tue_07-02-2009 etc.) and all the subfolder and file that are 7 days old. Right now i login to the remote server and delete the folders manually

Forfiles is included in Windows 2003 server and above, and in Vista and above, but I think there is some resource kit you can download to be able to use it on previous versions of Windows.
As for the folder deletion, I guess it can be done with something similar to the scripts I suggested in the original answer.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

Processing your reply...

Ask a Question

Free Guide: Managing storage for virtual environments

Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!

To follow this tag...

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy