Re: [PHP] having trouble with is_file() and is_dir() on 5.1.2
try using this, from php manual, clive ?php echo filetype('/etc/passwd'); // file echo filetype('/etc/');// dir ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] having trouble with is_file() and is_dir() on 5.1.2
# [EMAIL PROTECTED] / 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
Re: [PHP] having trouble with is_file() and is_dir() on 5.1.2
# [EMAIL PROTECTED] / 2007-01-23 09:14:15 +: readdir() returns only a basename, you need to be in the directory you're traversing (opendir(.) or opendir($dir); chdir($dir)) ... or prefix the basenames with the path you used in the opendir() call. -- 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
Re: [PHP] having trouble with is_file() and is_dir() on 5.1.2
On Jan 22, 2007, at 11:18 PM, clive wrote: everything without an extension is a directory You will notice that the only directory detected by this code is templates. There are no files detected by this code. Does this have something to do with stat cache? I want to make one array with directories and one array with files. I can't see any syntax or logic problems. Thanks in advance; JK As far as I know is_dir and is_file require a full path , as chris mentioned, how are you populating $cont; clive Thanks all for the replies, I think I got the message. Some times getting better at things can be a pain. I code and code and code and get use to writing code like the above and have it just work. Then I use a function I've never used before, is_file() and is_dir() and surprise... I have gotten past dumb syntax errors and screwy logic, it must be the os or something(?!). JK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] having trouble with is_file() and is_dir() on 5.1.2
On Tue, January 23, 2007 12:03 am, jekillen wrote: Hello php developers: I am having a problem with the following code: OS: FreeBSD v6.0 Apache 1.3.34 php 5.1.2 - $cont is an array produced from opening and reading a directory: for($i = 0; $i count($cont); $i++) { print $cont[$i].'br'; if(is_file($cont[$i])) { print is file: .$cont[$i].'br'; //array_push($files, $cont[$i]); } else if(is_dir($cont[$i])) { print is dir: .$cont[$i].br; //array_push($dirs, $cont[$i]); } } The print statements produce the following: collections groups in index.php lists.php new_multi.php new_single.php out pref_code pref_funct.php process.php requests rlists routing.php send.php steps.php store templates is dir: templates - only directory recognized (extra line breaks added here for readability) usr_config.php usr_pref.php everything without an extension is a directory You will notice that the only directory detected by this code is templates. There are no files detected by this code. Does this have something to do with stat cache? I want to make one array with directories and one array with files. I can't see any syntax or logic problems. Thanks in advance; is_file and is_dir are checking in the same dir as your PHP script, not the one you opened. So you are detecting that your PHP dir *also* happens to have a directory named templates which is a mere coincidence to the fact that the directory you opened had a directory named templates Use a FULL PATH when you are messing with files/dirs if at all possible, and your life will be much simpler. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] having trouble with is_file() and is_dir() on 5.1.2
jekillen wrote: Hello php developers: I am having a problem with the following code: OS: FreeBSD v6.0 Apache 1.3.34 php 5.1.2 - $cont is an array produced from opening and reading a directory: for($i = 0; $i count($cont); $i++) { print $cont[$i].'br'; if(is_file($cont[$i])) { print is file: .$cont[$i].'br'; //array_push($files, $cont[$i]); } else if(is_dir($cont[$i])) { print is dir: .$cont[$i].br; //array_push($dirs, $cont[$i]); } } I'd be guessing it's a path issue. Try prefixing the is_dir and is_file calls with the path to the directory they are in: $basedir = '/whatever'; for($i = 0; $i count($cont); $i++) { $fullpath = $basedir . '/' . $cont[$i]; if (is_file($fullpath)) { . } -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] having trouble with is_file() and is_dir() on 5.1.2
Haven't really looked at it - but elseif is one word - or do you mean else then an if... Respectfully, Ligaya Turmelle -Original Message- From: jekillen [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 23, 2007 4:03 PM To: PHP General List Subject: [PHP] having trouble with is_file() and is_dir() on 5.1.2 Hello php developers: I am having a problem with the following code: OS: FreeBSD v6.0 Apache 1.3.34 php 5.1.2 - $cont is an array produced from opening and reading a directory: for($i = 0; $i count($cont); $i++) { print $cont[$i].'br'; if(is_file($cont[$i])) { print is file: .$cont[$i].'br'; //array_push($files, $cont[$i]); } else if(is_dir($cont[$i])) { print is dir: .$cont[$i].br; //array_push($dirs, $cont[$i]); } } The print statements produce the following: collections groups in index.php lists.php new_multi.php new_single.php out pref_code pref_funct.php process.php requests rlists routing.php send.php steps.php store templates is dir: templates - only directory recognized (extra line breaks added here for readability) usr_config.php usr_pref.php everything without an extension is a directory You will notice that the only directory detected by this code is templates. There are no files detected by this code. Does this have something to do with stat cache? I want to make one array with directories and one array with files. I can't see any syntax or logic problems. Thanks in advance; JK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] having trouble with is_file() and is_dir() on 5.1.2
everything without an extension is a directory You will notice that the only directory detected by this code is templates. There are no files detected by this code. Does this have something to do with stat cache? I want to make one array with directories and one array with files. I can't see any syntax or logic problems. Thanks in advance; JK As far as I know is_dir and is_file require a full path , as chris mentioned, how are you populating $cont; clive -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] having trouble with is_file() and is_dir() on 5.1.2
On Jan 22, 2007, at 10:20 PM, Chris wrote: jekillen wrote: Hello php developers: I am having a problem with the following code: OS: FreeBSD v6.0 Apache 1.3.34 php 5.1.2 - $cont is an array produced from opening and reading a directory: for($i = 0; $i count($cont); $i++) { print $cont[$i].'br'; if(is_file($cont[$i])) { print is file: .$cont[$i].'br'; //array_push($files, $cont[$i]); } else if(is_dir($cont[$i])) { print is dir: .$cont[$i].br; //array_push($dirs, $cont[$i]); } } I'd be guessing it's a path issue. Try prefixing the is_dir and is_file calls with the path to the directory they are in: $basedir = '/whatever'; for($i = 0; $i count($cont); $i++) { $fullpath = $basedir . '/' . $cont[$i]; if (is_file($fullpath)) { . } -- Postgresql php tutorials http://www.designmagick.com/ 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. But I will take you suggestion. Thanks for the reply; JK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php