Can anyone explain the weird error i am getting? I am running the script below which deletes any .txt files that are older than 7 days old.
$dh = opendir("./");
while (($filename = readdir($dh))!== false) {
if ((substr($filename, -4) == ".txt")&&(filemtime($filename) < (time()-604800))) {
unlink ("$filename");
}
}
closedir($dh);
The script runs fine when the current directory (./) is used. However I really want to run the script on a sub-directory called "files". However when i change opendir("./"); to opendir("./files"); i get the following errors:
<b>Warning</b>: filemtime() [<a href='http://www.php.net/function.filemtime'>function.filemtime</a>]: Stat failed for 991043164.txt (errno=2 - No such file or directory) in <b>/home/sites/www.testweb.xx/web/jt_site_22_11_02/cards/createcardsafe_rock.php</b> on line <b>72</b><br />
<br />
<b>Warning</b>: unlink(991043164.txt) [<a href='http://www.php.net/function.unlink'>function.unlink</a>]: No such file or directory in <b>/home/sites/www.testweb.xx/web/jt_site_22_11_02/cards/createcardsafe_rock.php</b> on line <b>73</b><br />
This suggests to me that the script is reading the directory and finding the files but when it comes to reading their creation date and deleting them it suddenly can't find them.
Can anyone tell me what i am missing?