http://php.net/manual/en/class.filesystemiterator.php
I noticed that FilesystemIterator
returns the files ordered by name. Can anyone confirm this is true and it always happens? I haven't found anything in the docs.
Another question, is there any way to get the files ordered by the creation time on the disk? getCTime()
seems to return the change time so I can't use it with usort()
I did some digging into PHP internals.
If I am not mistaken, the __construct method of FileSystemIterator ends up using the VCWD_OPENDIR
C
macro : https://github.com/php/php-src/blob/2f443acad19816e29b0c944426238d9f23af1ae2/main/streams/plain_wrapper.c#L908
This is a macro to the C
Function opendir()
.
By looking at the documentation of that function, I can't see anything that would allow to define any kind of order : http://pubs.opengroup.org/onlinepubs/009695399/functions/opendir.html
Knowing that, I would assume that the order is not enforced and could vary depending on the type of filesystem used (fat32, ntfs, etc.).
Therefore, If I were you - to be safe - I would implement a PHP function that would order them the way I want.
For your 2nd question, check : PHP: how can I get file creation date?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With