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.
Strange directory output, isn't the same?
Strange directory output, isn't the same?
Regards Stone Oakvalley
Currently @ PB 5.70
Currently @ PB 5.70
Re: Strange directory output, isn't the same?
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.
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.
-
- Addict
- Posts: 4519
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Strange directory output, isn't the same?
... and please do not ask comprehension questions in the "Bug reports" section of the forum!DK_PETER wrote:Use a list or array and do a sort...
Last edited by Little John on Sun Aug 20, 2017 5:40 pm, edited 1 time in total.
Re: Strange directory output, isn't the same?
PureBasics Directory-Commands return a unsorted list, in the order of the directory-entries in the file system.
Re: Strange directory output, isn't the same?
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.
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
Currently @ PB 5.70
Re: Strange directory output, isn't the same?
There are many nitpick bugs in Windows 7,10.
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.
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