Click to See Complete Forum and Search --> : Check file attributes and delete [Resolved]
ober0330
Jul 19th, 2004, 11:05 AM
I need to know how to check the create time on all the files in a certain folder on the server and delete them if they are older than 30 minutes.
Users will be creating reports on the server and then downloading them. I'm giving them 30 minutes to create the report and download it before I remove it from the server so I'm not hogging a bunch of room on the server HD.
I know I have to use unlink to delete the files, but how do I check the file attributes?
The Hobo
Jul 19th, 2004, 11:30 AM
I know that fileatime() gives the last access time and that filemtime() gives the last time it was modified...but I don't know of anything that'll give the time it was created.
ober0330
Jul 19th, 2004, 11:57 AM
Well the modify time and creation time will be the same since the file will only be downloaded after it has been created.
The Hobo
Jul 19th, 2004, 01:56 PM
Those functions, by the way, take in the name of a file and return a unix timestamp.
ober0330
Jul 19th, 2004, 02:37 PM
Right... and I'll just use maketime to create a timestamp of 30 minutes previous to the current time. If it meets the criteria, it gets the axe. Thanks.
visualAd
Jul 20th, 2004, 04:13 AM
Originally posted by ober0330
Right... and I'll just use maketime to create a timestamp of 30 minutes previous to the current time. If it meets the criteria, it gets the axe. Thanks.
No need to do that. A unix timestamp is in seconds. So all you need to do is define a variable which holds the number of seconds in 30 minutes:
$seconds_30min = 30 * 60;
$ctime = filectime ($file);
if ($seconds_30min + $ctime < time ())
echo ('file is older than 30 mins');
ober0330
Jul 20th, 2004, 07:32 AM
Ok, next problem... how do I loop through all the files in a folder? I don't know their names other than the fact that it'll be "qry" and then a time/date stamp and then ".csv".
visualAd
Jul 20th, 2004, 07:36 AM
http://uk.php.net/manual/en/ref.dir.php
ober0330
Jul 20th, 2004, 08:17 AM
Excellent. Thanks for the tip. It looks like I'll be using scandir().
:thumb:
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.