View Full Version : delete all files in folder error

06-28-2010, 11:56 AM
this script deletes files older then 10 minutes. It works but if the directory is empty it throws out this error message:

in file /mdwgold/index.php on line 52: Invalid argument supplied for foreach()

$captchaFolder = '../mdwgold/uploads/';
$fileTypes = '*.*';
$expire_time = 10;
foreach (glob($captchaFolder . $fileTypes) as $Filename) {
$FileCreationTime = filectime($Filename);
$FileAge = time() - $FileCreationTime;
if ($FileAge > ($expire_time * 60)){
print "The file $Filename is older than $expire_time minutes\n";


How can I alter the coding so no error will come up?

06-28-2010, 12:54 PM
Use glob before the loop and see if there is anything to be deleted before starting the loop. If nothing is returned by glob do nothing otherwise use your loop.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum