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

From: Date: Tue, 23 Jan 2007 09:14:15 +0000
Subject: Re: having trouble with is_file() and is_dir() on 5.1.2
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-247615@lists.php.net to get a copy of this message
# jekillen@prodigy.net / 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

« previous php.general (#247615) next »