I compiled a little application with PB 5.70 under Windows and I wanted to compile the same application with PB 5.70 under Linux.
Everything worked well with one small glitch. In part of the code there is a requirement to create a simple text file containing the paths to the (12,000+) files in a specific directory. The code reads the paths into a List and then uses a simple ForEach loop to write the text file. With the exception of the "\" and "/" the code for both OS is identical and works perfectly. The only difference is that the resulting Windows text file is sorted in alphanumeric order and the Linux text file is unsorted.
Not an insurmountable problem, I have become accustomed to writing gobs of extra code to workaround the endless limitations of Linux, so an additional sort routine will be no big deal.
However, I would like to know why identical code working on identical files produces different results. Is this something to do with the way PB handles Lists or are there other factors related to the OS that influence this difference?
Dave
Why a difference in List output?
Re: Why a difference in List output?
Does your code sort the lists manually after generating them? If not, why not? Then the results will be the same on Windows/Linux.davebar wrote:the resulting Windows text file is sorted in alphanumeric order and the Linux text file is unsorted.
Re: Why a difference in List output?
Is it due to the paths being obtained in an unsorted order from reading the directory?
Re: Why a difference in List output?
My post said:BarryG wrote:Does your code sort the lists manually after generating them? If not, why not? Then the results will be the same on Windows/Linux.davebar wrote:the resulting Windows text file is sorted in alphanumeric order and the Linux text file is unsorted.
"With the exception of the "\" and "/" the code for both OS is identical"
So the answer to your question is NO there is zero sorting.
Obviously I can sort the garbage Linux output, but I am NOT look looking for a workaround, I am trying to understand why identical code produces different results.
Re: Why a difference in List output?
Not sure if that's a possibility or not, because the reading code is identical on both OS.Demivec wrote:Is it due to the paths being obtained in an unsorted order from reading the directory?
The code is simply working through the files in a directory and reading the them into a list.
Re: Why a difference in List output?
Hi,
I assume you're using ExamineDirectory() and NextDirectoryEntry().
These internally call OS functions, which iterate through the entries in the filesystem. But they are not always guaranteed to be in sorted order!
If you REQUIRE the files to be sorted, you have to put them in some sort of list and sort it yourself (eg. call SortList()).
It's not a Windows vs. Linux thing, it depends on the filesystem format of the drive you're examining. Like FAT/32, which is older, can definitely give unsorted results on Windows.
Windows own reference:
https://docs.microsoft.com/en-us/window ... dnextfilea
I assume you're using ExamineDirectory() and NextDirectoryEntry().
These internally call OS functions, which iterate through the entries in the filesystem. But they are not always guaranteed to be in sorted order!
If you REQUIRE the files to be sorted, you have to put them in some sort of list and sort it yourself (eg. call SortList()).
It's not a Windows vs. Linux thing, it depends on the filesystem format of the drive you're examining. Like FAT/32, which is older, can definitely give unsorted results on Windows.
Windows own reference:
https://docs.microsoft.com/en-us/window ... dnextfilea
Code: Select all
The order in which the search returns the files, such as alphabetical order, is not guaranteed, and is dependent on the file system. If the data must be sorted, the application must do the ordering after obtaining all the results.
Re: Why a difference in List output?
Thanks kenmo,
You have pretty much confirmed what I believed to be the reason for the difference.
Yes I was using ExamineDirectory() and NextDirectoryEntry() to construct the list.
The Windows machine FS is ntfs & the Linux machine FS is ext4
Since I hadn't needed to call SortList() in the original Windows code, it hadn't occurred to me that it would be needed for the Linux code.
Obviously calling SortList() was the solution I used.
Dave
You have pretty much confirmed what I believed to be the reason for the difference.
Yes I was using ExamineDirectory() and NextDirectoryEntry() to construct the list.
The Windows machine FS is ntfs & the Linux machine FS is ext4
Since I hadn't needed to call SortList() in the original Windows code, it hadn't occurred to me that it would be needed for the Linux code.
Obviously calling SortList() was the solution I used.
Dave
Re: Why a difference in List output?
Because even though your code is identical, the results from each OS filesystem is different.davebar wrote:I am trying to understand why identical code produces different results.
Just like I already told you to do, before Kenmo convinced you.davebar wrote:SortList() was the solution I used.
Re: Why a difference in List output?
Just like I already told you to do, before Kenmo convinced you.[/quote]davebar wrote:SortList() was the solution I used.
No Kenmo did not convince me to do anything I had not already done long before I first posted the question.
You keep responding in a way that suggests I am looking for an answer to resolve a problem.
In a previous reply to you I wrote:
I am NOT look looking for a workaround, I am trying to understand why identical code produces different results
Re: Why a difference in List output?
I've been in that situation too. Not just Linux, but a USB/external drive on Windows can give you unsorted results Cheers.davebar wrote:Since I hadn't needed to call SortList() in the original Windows code, it hadn't occurred to me that it would be needed for the Linux code.