note 83307 added to function.is-dir

From: Date: Tue, 20 May 2008 10:28:20 +0000
Subject: note 83307 added to function.is-dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-139551@lists.php.net to get a copy of this message
Well, "John Doe's function" doesn't return the good value when $file != '.' && $file != '..' it must return false and not true ! Moreover, as the latest contributor told us, the directory have to be closed before returning. This one is far safer ;-) : <?php function is_empty_dir($dir) { if ($dh = @opendir($dir)) { while ($file = readdir($dh)) { if ($file != '.' && $file != '..') { closedir($dh); return false; } } closedir($dh); return true; } else return false; // whatever the reason is : no such dir, not a dir, not readable } ?> ---- Server IP: 195.221.21.36 Probable Submitter: 82.238.203.157 ---- Manual Page -- http://www.php.net/manual/en/function.is-dir.php Edit -- https://master.php.net/note/edit/83307 Del: integrated -- https://master.php.net/note/delete/83307/integrated Del: useless -- https://master.php.net/note/delete/83307/useless Del: bad code -- https://master.php.net/note/delete/83307/bad+code Del: spam -- https://master.php.net/note/delete/83307/spam Del: non-english -- https://master.php.net/note/delete/83307/non-english Del: in docs -- https://master.php.net/note/delete/83307/in+docs Del: other reasons-- https://master.php.net/note/delete/83307 Reject -- https://master.php.net/note/reject/83307 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139551) next »