Bug #70734 [Opn->Nab]: RecursiveDirectoryIterator output is not sorted
| From: | bwoebi@php.net | Date: | Sun, 18 Oct 2015 23:19:58 +0000 |
| Subject: | Bug #70734 [Opn->Nab]: RecursiveDirectoryIterator output is not sorted | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-196680@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70734&edit=1
ID: 70734
Updated by: bwoebi@php.net
Reported by: messiah at os dot pl
-Summary: Error
+Summary: RecursiveDirectoryIterator output is not sorted
-Status: Open
+Status: Not a bug
Type: Bug
Package: *Directory/Filesystem functions
Operating System: Linux
PHP Version: 5.4.45
Block user comment: N
Private report: N
New Comment:
The manual does not guarantee anything about the order. RecursiveDirectoryIterator (and the other
filesystem based iterators iterate in the order the OS returns the files to them.
That it is sorted on Windows is not guaranteed by PHP, it just seems to happen due to the underlying
implementation in the Windows kernel.
Previous Comments:
------------------------------------------------------------------------
[2015-10-18 21:02:53] messiah at os dot pl
Description:
------------
RecursiveDirectoryIterator() with RecursiveIteratorIterator() not sorting all values by name like on
Windows. Try script below on Windows and Linux. This should be sorted by default by name folder and
subfolder then next filename. Fix this. I tessted this on PHP 5.5.24 Linux and 5.4.8 Linux and
5.6.11 Windows
Test script:
---------------
<?php
$MójFolder = __DIR__;
$Pliki = array('Pliki'=>array(), 'Foldery'=>array());
$SkanerKatalogówIPlików = new RecursiveDirectoryIterator($MójFolder,
RecursiveDirectoryIterator::SKIP_DOTS);
$SkanujWszystkiePodkatalogi = new RecursiveIteratorIterator($SkanerKatalogówIPlików,
RecursiveIteratorIterator::SELF_FIRST);
foreach($SkanujWszystkiePodkatalogi as $WszystkiePlikiIFoldery){
if($WszystkiePlikiIFoldery->isDir()){
$Pliki['Foldery'][] = $WszystkiePlikiIFoldery .'/';
}elseif($WszystkiePlikiIFoldery->isFile()){
$Pliki['Pliki'][] = $WszystkiePlikiIFoldery->getPathname();
}
}
#print_r($Pliki);
return $Pliki;
Expected result:
----------------
Add sorting by name example:
folder/subfolder1/filename.php
folder/subfolder1/filename1.php
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70734&edit=1