note 71544 deleted from function.is-dir by bjori

From: Date: Tue, 05 Dec 2006 15:07:16 +0000
Subject: note 71544 deleted from function.is-dir by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-120303@lists.php.net to get a copy of this message
Note Submitter: acehole at campus dot ie Reason: in docs ---- 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 ); } } } ?>

« previous php.notes (#120303) next »