[Solved] - ExamineDirectory() or OS X bug?

Just starting out? Need help? Post your questions and find answers here.
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

[Solved] - ExamineDirectory() or OS X bug?

Post by J. Baker »

The following code has obviously worked fine for years but now loads files out of order. Well, this is not my exact code but posting PureBasic example for reference. It does the same. For example, images in a numerical order.

Image00001.png
Image00002.png
Image00003.png
Etc.

I believe this may be an OS X bug though. An app I made has worked fine for years until some one recently pointed this issue out to me.

Code: Select all

ImageFolder$ = PathRequester("Select Image Folder...", "")

If ExamineDirectory(0, ImageFolder$, "*.*")  
    While NextDirectoryEntry(0)
      If DirectoryEntryType(0) = #PB_DirectoryEntry_File
        Type$ = "[File] "
        Size$ = " (Size: " + DirectoryEntrySize(0) + ")"
      Else
        Type$ = "[Directory] "
        Size$ = "" ; A directory doesn't have a size
      EndIf
      
      Debug Type$ + DirectoryEntryName(0) + Size$
    Wend
    FinishDirectory(0)
  EndIf
Last edited by J. Baker on Wed Apr 29, 2020 10:23 pm, edited 1 time in total.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
STARGÅTE
Addict
Addict
Posts: 2090
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: ExamineDirectory() or OS X bug?

Post by STARGÅTE »

To my knowledge ExamineDirectory() does not return a sorted file list, on all OS.
And if it looks like a sorted list, it is just because of the currently used file system.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: ExamineDirectory() or OS X bug?

Post by kenmo »

ExamineDirectory() does not guarantee sorted results, even if it often appears so!

I believe it returns the results in the order as the API functions it's internally using. Which vary with OS, Filesystem, drive etc.

I've noticed USB drives (FAT32 maybe?) can return VERY unsorted results.


If you want to guarantee sorted files in your program, I recommend adding them to a String List and calling SortList() afterward.

If the results are mostly in order anyway, the performance hit should be negligible.


** STARGATE beat me :)
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: ExamineDirectory() or OS X bug?

Post by J. Baker »

Yes, you both are correct but the file naming order has always worked until recently. I will look into SortList(). Thanks! ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: ExamineDirectory() or OS X bug?

Post by J. Baker »

Ok, so if on OS X I have the folder set to arrange and sort by name, shouldn't NextDirectoryEntry(0) list them the order they are in? I'm just having a hard time understanding why they are being listed out of order if the directory has them in order.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: ExamineDirectory() or OS X bug?

Post by freak »

Directories don't have a defined order. If it looks that way it is just luck or an artifact of the underlying file system. You can't rely on it.

If you need an order, you have to sort the result.
quidquid Latine dictum sit altum videtur
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: ExamineDirectory() or OS X bug?

Post by J. Baker »

That's what I'll do then. Just wonder why it worked that way for so long.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

Re: ExamineDirectory() or OS X bug?

Post by Wolfram »

I think the order is dependent the way you copy each file.
Try to copy file by file and see whats happened.
macOS Catalina 10.15.7
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: ExamineDirectory() or OS X bug?

Post by J. Baker »

Wolfram wrote:I think the order is dependent the way you copy each file.
Try to copy file by file and see whats happened.
I'm not understanding?
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: [Solved] - ExamineDirectory() or OS X bug?

Post by J. Baker »

I used SortList() and that worked great. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
Post Reply