note 104681 added to function.scandir

From: Date: Thu, 30 Jun 2011 09:53:06 +0000
Subject: note 104681 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-181090@lists.php.net to get a copy of this message
Gerard, thanks for your code snippet. I've just been looking for something like that. But I had to change some little things: - Pay attention to a separating slash / backslash between $path and $file. If it's not there, the output is wrong. - The dirs were sorted reversely and the files where ok. My solution was: <?php function scandirSorted ($path) { $files = array(); $dirs = array(); foreach (scandir($path) as $file) { if (is_file($path . "/" . $file)) { // Linux: "/", Windows: "\\" array_push($files, $file); } else { array_push($dirs, $file); } } return array_merge($dirs, $files); } ?> So I'm filling up two different arrays. One with directories and one with files. In the end, I return them as one single array. ---- Server IP: 85.214.154.209 Probable Submitter: 213.183.84.168 ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- https://master.php.net/note/edit/104681 Del: integrated -- https://master.php.net/note/delete/104681/integrated Del: useless -- https://master.php.net/note/delete/104681/useless Del: bad code -- https://master.php.net/note/delete/104681/bad+code Del: spam -- https://master.php.net/note/delete/104681/spam Del: non-english -- https://master.php.net/note/delete/104681/non-english Del: in docs -- https://master.php.net/note/delete/104681/in+docs Del: other reasons-- https://master.php.net/note/delete/104681 Reject -- https://master.php.net/note/reject/104681 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#181090) next »