RE: Re: most latest file

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

 



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) {
     $time = fileatime($file);
     $lastModifiedFile = $file;
   }
}

closedir($handle);
echo $lastModifiedFile;


-----Original Message-----
From: Jason Barnett [mailto:jasbarne@xxxxxxxxxxx]
Sent: Monday, April 26, 2004 11:18 PM
To: php-windows@xxxxxxxxxxxxx
Subject:  Re: most latest file


Harpreet wrote:

> Actually I have a backups folder that gets once a day backups of the
> database automaticcaly. I want to be able to know the name fo the the
latest
> file to do the restore. The name of the files have the time stamp and plus
> file has a time last mdified date attached to it.
>
> How can I know which file got restored last using php and also the file
> name.
>
> Thanks

<?php

$directory = 'path/to/backups/directory';

$handle = opendir($directory) {
while (false !== ($file = readdir($handle))) {
   if ($file != "." && $file != ".." && fileatime($file) > $time) {
     $time = fileatime($file);
     $lastModifiedFile = $file;
   }
}

closedir($handle);
echo $lastModifiedFile;

?>

http://www.php.net/readdir
http://www.php.net/manual/en/function.fileatime.php

or, to check file creation times:

http://www.php.net/manual/en/function.filectime.php

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

-- 
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