Re: having trouble with is_file() and is_dir() on 5.1.2

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

 



# jekillen@xxxxxxxxxxx / 2007-01-22 23:26:06 -0800:
> On Jan 22, 2007, at 10:20 PM, Chris wrote:
> >$basedir = '/whatever';
> >
> >for($i = 0; $i < count($cont); $i++) {
> >  $fullpath = $basedir . '/' . $cont[$i];
> >  if (is_file($fullpath)) {
> >  .....
> >}
> 
> Ok, I hope I can get this to work. The code
> I copied here was code that was in the directory
> reading loop, where I would have guess that
> it would have the path info, but it did the same
> thing.

readdir() returns only a basename, you need to be in
the directory you're traversing (opendir(".") or
opendir($dir); chdir($dir)).  Compare this:

function is_file()     { return test -f $1; }
function is_dir()      { return test -d $1; }
function file_exists() { return test -e $1; }

mkdir child
touch child/a child/b child/c
echo current directory: $(pwd)
for f in $(ls child); do
  is_file     $f && echo is_file $f
  is_dir      $f && echo is_dir $f
  file_exists $f && echo file_exists $f
  is_file     child/$f && echo is_file child/$f
  is_dir      child/$f && echo is_dir child/$f
  file_exists child/$f && echo file_exists child/$f
done

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE.             http://bash.org/?255991

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux