I just got PHP-CLI working on my Windows machine so I could create scripts using PHP. However, I'm trying to write a script to cleanup my Firefox downloads folder of files older than X number of days, but I can't seem to get the filemtime() function working.
Here is the function I wrote:
function deleteOldFiles($dir, $days) {
$mydir = opendir($dir);
while(($file = readdir($mydir)) !== false) {
if($file != "." && $file != ".." && (filemtime($dir.$file) <= time() - ($days * 86400))) {
//unlink($dir.$file) or DIE("Failed to delete $dir$file<br />");
echo filemtime($dir.$file);
}
}
closedir($mydir);
}
And upon running this I get the following error for every file:
Warning: filemtime(): stat failed for E:\My Documents\Downloadsphp-5.3.0-nts-Win32-VC9-x86.msi in E:\_scripts\cleanupDownloads\cleanupDownloads.php on line 10
From the research I've done, filemtime() should work in Windows. What am I doing wrong?