Welcome to CGI City - One of the biggest WWW Resources for CGI and Perl materials
Tips and Tutorials
How do I use Perl to automatically delete files in a directory?

Scenario: you have a directory that accumulates files eating up precious disk space and you want a way to delete them automatically.

The following code example will open and read a given directory and delete all files ending with .txt that are more than a day old:

The above code may be modified to suit your own application.

Note: One way for this to be "automatically executed" is for the user to create a cron job. Another way is to add the above code as a sub-routine to a frequently-run CGI script. That way, every time the frequently-run CGI script is called and executed, the sub-routine checks for day-old files in the given directory and purges thems as needed.

-oOo-

Back to Tips and Tutorials


Search For:
Quick jump to
Home | About Us | Contact Us | Link To Us | Search
Tips & Tutorials | References | Books | Add A Resource
Custom Programming Services | Advertise
Disclaimer | Privacy Policy

Copyright © 1998-2099    CGI City    All Rights Reserved
All original materials contained herein including text, images, and original scripts written by CGI City, are copyrighted by CGI City. All other scripts and materials are copyrighted by their respective authors/owners.