note 71544 added to function.is-dir
| From: | aceholeatcampusdotie at osu1 dot php dot net | Date: | Tue, 05 Dec 2006 04:48:47 +0000 |
| Subject: | note 71544 added to function.is-dir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120291@lists.php.net to get a copy of this message | ||
I find the following method for testing if the folder's contents are themselves folders. Like
alan rezende said, "the function is_dir will always return false if the handle acquired with
opendir is not from the current working directory". This solution gets around this by
prepending the path to the item being tested (the line with * at the end).
<?php
$dir = "Folder";
if ($dh = opendir($dir)) {
// List all files and folders
while ( ($file = readdir($dh)) != false ) {
// Neat way to accurately check for a subfolder....
if ( is_dir("$dir/$file") && $file != "." && $file !=
"..") { //*
echo ( "Found a subfolder: " . $file );
} else {
echo ( "Found a file: " . $file );
}
}
}
?>
----
Server IP: 216.235.15.211
Probable Submitter: 205.206.184.159
----
Manual Page -- http://www.php.net/manual/en/function.is-dir.php
Edit -- https://master.php.net/note/edit/71544
Del: integrated -- https://master.php.net/note/delete/71544/integrated
Del: useless -- https://master.php.net/note/delete/71544/useless
Del: bad code -- https://master.php.net/note/delete/71544/bad+code
Del: spam -- https://master.php.net/note/delete/71544/spam
Del: non-english -- https://master.php.net/note/delete/71544/non-english
Del: in docs -- https://master.php.net/note/delete/71544/in+docs
Del: other reasons-- https://master.php.net/note/delete/71544
Reject -- https://master.php.net/note/reject/71544
Search -- https://master.php.net/manage/user-notes.php