Re: Re: most latest file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux