Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting folders that are older then X Days

Status
Not open for further replies.

sharapov

MIS
May 28, 2002
106
US
My backups run every day and generate a folder(directory) with *.sql files in it. How can I go through a spesific directory and delete all folders (with contents) contained in this directory that are older then 10 days (for example) from today's date.

Thanks.
 
I would get a handle to the directory using opendir(). I would then fetch each filename (skipping "." and "..") using readdir().

For each filename I fetched from the directory using readdir(), I would hand the filename to stat() to find out the file times.

I would then compare the file's ctime to the current timestamp. If the file is older than 10 days, I would delete it using unlink().

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top