RE: [PHP-WIN] Re: most latest file
| From: | Harpreet | Date: | Wed, 28 Apr 2004 03:56:17 +0000 |
| Subject: | RE: [PHP-WIN] Re: most latest file | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-23565@lists.php.net to get a copy of this message | ||
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@indiana.edu]
Sent: Monday, April 26, 2004 11:18 PM
To: php-windows@lists.php.net
Subject: [PHP-WIN] 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