note 90942 added to function.is-dir

From: Date: Sun, 17 May 2009 17:09:12 +0000
Subject: note 90942 added to function.is-dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-154947@lists.php.net to get a copy of this message
<?php public static function isEmptyDir($dir){ return (($files = @scandir($dir)) && count($files) <= 2); } ?> This function is nice, but wrong. If scandir($dir) fails, function will return false, meaning that directory ist not empty. Use negation logic: <?php public static function isEmptyDir($dir){ return (!(($f = @scandir($e)) && count($f) > 2)); } ?> ---- Server IP: 217.160.72.57 Probable Submitter: 84.57.173.63 ---- Manual Page -- http://www.php.net/manual/en/function.is-dir.php Edit -- https://master.php.net/note/edit/90942 Del: integrated -- https://master.php.net/note/delete/90942/integrated Del: useless -- https://master.php.net/note/delete/90942/useless Del: bad code -- https://master.php.net/note/delete/90942/bad+code Del: spam -- https://master.php.net/note/delete/90942/spam Del: non-english -- https://master.php.net/note/delete/90942/non-english Del: in docs -- https://master.php.net/note/delete/90942/in+docs Del: other reasons-- https://master.php.net/note/delete/90942 Reject -- https://master.php.net/note/reject/90942 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154947) next »