Strange directory output, isn't the same?

Just starting out? Need help? Post your questions and find answers here.
User avatar
oakvalley
User
User
Posts: 76
Joined: Sun Aug 08, 2004 6:34 pm
Location: Norway
Contact:

Strange directory output, isn't the same?

Post by oakvalley »

Hi there,

I have 4 files in a directory on Windows 7 64bit English:

franç.txt
franš.txt
franþ.txt
ranã.txt

In a normal directory via windows standard explorer or Total Commander they are listed exactly in that order assumingly sorted alphabetically, while purebasic's Examinedirectory manages to shift the 2 middle ones, so they appear like this:

franç.txt
franþ.txt
franš.txt

ranã.txt

I'm trying with both PB5.60 (unicode) and PB5.31 both same result.
All chars are within 0-255 ASCII Range.
ç = $E7 = 231
š = $9A = 154
þ = $FE = 254

ã = $E3 = 227

How can this happen? Doesn't Purebasic read the directory as each item comes along? In that case both listings should be the same?

Why are 154 and 254 flipped in PureBasic's output?

I used the standard ExamineDirectory() example from PureBasic help. It should be noted that issuing a "DIR" command in a standard windows console outputs the same as Purebasic does, where the 2 middle items are flipped.
Regards Stone Oakvalley
Currently @ PB 5.70
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Strange directory output, isn't the same?

Post by DK_PETER »

Use a list or array and do a sort...

Code: Select all

Global NewList files.s()

Declare.i ExamineDir(dirname.s, Pattern.s = "*") 
Declare.s slash(direct.s)

Procedure.s slash(direct.s)
  If Right(direct,1) <> "\"
    ProcedureReturn direct + "\"
  Else
    ProcedureReturn direct
  EndIf
EndProcedure

Procedure.i ExamineDir(dirname.s, Pattern.s = "*") 
    Protected dir.i, Filename.s
    dir = ExamineDirectory(#PB_Any, dirname, Pattern) 
    If dir > 0
      While NextDirectoryEntry(dir) 
        Filename = DirectoryEntryName(dir) 
        If DirectoryEntryType(dir) = #PB_DirectoryEntry_Directory And Filename <> "." And Filename <> ".." 
          ExamineDir(slash(dirname) + Filename)
        ElseIf DirectoryEntryType(dir) = #PB_DirectoryEntry_File And Filename <> "." And Filename <> ".."
          AddElement(files())
          files() = slash(dirname) + Filename
        EndIf 
      Wend 
      FinishDirectory(dir) 
    EndIf 
    ;Add to the list and sort after search...
    SortList(files(), #PB_Sort_Ascending)
    ForEach files()
      Debug files()
    Next 
    ProcedureReturn #True
  EndProcedure 
  
  ExamineDir("E:\texttest", "*.txt")
  
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Strange directory output, isn't the same?

Post by Little John »

DK_PETER wrote:Use a list or array and do a sort...
... and please do not ask comprehension questions in the "Bug reports" section of the forum!
Last edited by Little John on Sun Aug 20, 2017 5:40 pm, edited 1 time in total.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: Strange directory output, isn't the same?

Post by GPI »

PureBasics Directory-Commands return a unsorted list, in the order of the directory-entries in the file system.
User avatar
oakvalley
User
User
Posts: 76
Joined: Sun Aug 08, 2004 6:34 pm
Location: Norway
Contact:

Re: Strange directory output, isn't the same?

Post by oakvalley »

Yes, into an array it works as intended, sorting works. I tried that too.

However, for my routine I simply wanted to use the OS own sorting of filenames to get stuff sorted "for free" just by reading the directory 1-by-1.
With your approach one have to add more code + spend time on sorting.

Its basically just the wierdness of Windows that sometimes makes me wonder and freak out, where is the logic for that behaviour, when thinking items
in a directory, you would expect them to be sorted alphabetically in Windows Explorer, Command Console and PB as the same.

Guess its not a bug in PB - but something to be aware of.
Regards Stone Oakvalley
Currently @ PB 5.70
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Strange directory output, isn't the same?

Post by skywalk »

There are many nitpick bugs in Windows 7,10. :idea:
Ex. Select several files in File Explorer, and do a Shift+RM Click -> Copy as path.
Then paste into a text editor. You'll see the order is different than your original selection.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply