Page 1 of 1

Why a difference in List output?

Posted: Sun May 12, 2019 9:53 pm
by davebar
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

Re: Why a difference in List output?

Posted: Sun May 12, 2019 10:17 pm
by BarryG
davebar wrote:the resulting Windows text file is sorted in alphanumeric order and the Linux text file is unsorted.
Does your code sort the lists manually after generating them? If not, why not? Then the results will be the same on Windows/Linux.

Re: Why a difference in List output?

Posted: Sun May 12, 2019 10:21 pm
by Demivec
Is it due to the paths being obtained in an unsorted order from reading the directory?

Re: Why a difference in List output?

Posted: Sun May 12, 2019 10:50 pm
by davebar
BarryG wrote:
davebar wrote:the resulting Windows text file is sorted in alphanumeric order and the Linux text file is unsorted.
Does your code sort the lists manually after generating them? If not, why not? Then the results will be the same on Windows/Linux.
My post said:
"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?

Posted: Sun May 12, 2019 10:56 pm
by davebar
Demivec wrote:Is it due to the paths being obtained in an unsorted order from reading the directory?
Not sure if that's a possibility or not, because the reading code is identical on both OS.
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?

Posted: Mon May 13, 2019 1:52 am
by kenmo
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

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?

Posted: Mon May 13, 2019 8:22 am
by davebar
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

Re: Why a difference in List output?

Posted: Mon May 13, 2019 8:54 am
by BarryG
davebar wrote:I am trying to understand why identical code produces different results.
Because even though your code is identical, the results from each OS filesystem is different.
davebar wrote:SortList() was the solution I used.
Just like I already told you to do, before Kenmo convinced you.

Re: Why a difference in List output?

Posted: Mon May 13, 2019 9:32 am
by davebar
davebar wrote:SortList() was the solution I used.
Just like I already told you to do, before Kenmo convinced you.[/quote]

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?

Posted: Mon May 13, 2019 1:05 pm
by kenmo
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.
I've been in that situation too. Not just Linux, but a USB/external drive on Windows can give you unsorted results :) Cheers.