Why a difference in List output?

Everything else that doesn't fall into one of the other PB categories.
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

Why a difference in List output?

Post 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
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Why a difference in List output?

Post 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.
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Why a difference in List output?

Post by Demivec »

Is it due to the paths being obtained in an unsorted order from reading the directory?
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

Re: Why a difference in List output?

Post 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.
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

Re: Why a difference in List output?

Post 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.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Why a difference in List output?

Post 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.
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

Re: Why a difference in List output?

Post 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
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Why a difference in List output?

Post 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.
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

Re: Why a difference in List output?

Post 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
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Why a difference in List output?

Post 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.
Post Reply