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.
Back to Tips and Tutorials