|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-07-28 16:03 UTC] degeberg@php.net
-Status: Open
+Status: Bogus
[2010-07-28 16:03 UTC] degeberg@php.net
[2010-07-28 16:07 UTC] d dot reade at ReadesGroupServices dot com
[2010-07-28 16:09 UTC] degeberg@php.net
[2010-07-28 16:14 UTC] d dot reade at ReadesGroupServices dot com
[2010-07-28 16:17 UTC] degeberg@php.net
[2010-07-28 16:40 UTC] d dot reade at ReadesGroupServices dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 19:00:01 2025 UTC |
Description: ------------ Using scandir() to fetch a list of folders/files in a folder. When I use foreach() and is_dir() to filter out folders from files, folders and files are being grouped together, almost like PHP thinks the folders are files. However if we use "." as the argument in the scandir() method, we get the desired results. The below test script assumes you've created the following folders/files: folderName/ folderName/testFolder1/ folderName/testFolder2/ folderName/testFile1 folderName/testFile2 These results occur using both the CLI and via a PHP page in the browser. Test script: --------------- <?php // Example 1 $scan = scandir("folderName"); foreach ($scan as $file) { if (is_dir($file)) { echo "Folder: ".$file."\n"; } else { echo "File: ".$file."\n"; } } ?> <?php // Example 2 $scan = scandir("."); foreach ($scan as $file) { if (is_dir($file)) { echo "Folder: ".$file."\n"; } else { echo "File: ".$file."\n"; } } ?> Expected result: ---------------- Example 2 gives the expected result: Folder: . Folder: .. File: testFile1 File: testFile2 Folder: testFolder1 Folder: testFolder2 Actual result: -------------- Example 1 gives the actual result: Folder: . Folder: .. File: testFile1 File: testFile2 File: testFolder1 File: testFolder2