RE: Re: most latest file

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

 



It works great when accessing local files but if i put a server path like
$dir="\\Servername\c\pathname";

Warning: opendir(\\servername\c\pathname) [function.opendir]: failed to open
dir: Invalid argument in D:\web\1.php on line 36

Line 36 is $handle = opendir($dir);

Thanks for all the help, it is greatly appreciated.


-----Original Message-----
From: Jason Barnett [mailto:jasbarne@xxxxxxxxxxx]
Sent: Wednesday, April 28, 2004 12:45 AM
To: php-windows@xxxxxxxxxxxxx
Subject: Re:  Re: most latest file


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

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