Re: Re: most latest file
| From: | Jason Barnett | Date: | Wed, 28 Apr 2004 04:45:28 +0000 |
| Subject: | Re: Re: most latest file | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-23566@lists.php.net to get a copy of this message | ||
Harpreet wrote:
I am using the below code and get the error Warning: fileatime() [function.fileatime]: Stat failed for abc.txt (errno=2 - No such file or directory) $dir='c:\pathname\temp'; $time='1'; $handle = opendir($dir); while (false !== ($file = readdir($handle))) { echo date("m-d-y H:i:s",fileatime($file)); if ($file != "." && $file != ".." && fileatime($file) > $time) {Is this where the error occured? This is what I get for giving code without testing it first. It seems that PHP is looking for 'abc.txt' in the current directory (instead of in c:\pathname\temp). Using an absolute path to $file instead of a relative one should work.
$time = fileatime($file);
$lastModifiedFile = $file;
}
}
closedir($handle);
echo $lastModifiedFile;
Modified code:
$dir='c:\pathname\temp';
$time='1';
$handle = opendir($dir);
while (false !== ($file = readdir($handle))) {
$absfile = $dir.'/'.$file;
echo date("m-d-y H:i:s",fileatime($file));
if ($file != "." && $file != ".." && fileatime($absfile) > $time) {
$time = fileatime($absfile);
$lastModifiedFile = $file;
}
}
closedir($handle);
echo $lastModifiedFile;