Save file order (a mystery)

I spent the last days to do (between other things) images resizing and noticed some differences, sometimes !

Explanaton:
I drop an image on a window, click a button and code resize and save that image at 5 different sizes.

Most of the times, the saved items appears in the target folder (same from where the image comes) in the alphabetical order.

But, sometimes it is in a different order. Annoying it is, but since I am curious, do you know what can happens ?

Before some ask for code, here’s the logic:

  1. Create a Picture1 (for size 1),
  2. Resize the Image and store it in Picture1
  3. Save Picture1 with its size 1 name,

Then do the same for the other sizes, then left.

Ideas ?

Not sure I understand the problem. Is it that the files sort differently than you expect, or that as you watch it run, they appear in the folder if different orders sometimes? Maybe give us an example listing showing this “different order”?

Imagine the code store the images as Resized1, Resized2, Resized3, Resized4 and Resized5 in an opened folder (macOS).

Sometimes, the files appears following that order (the code save order), and sometimes the order is different.

I do not takes note on what is the different order, but it is not the one I expected (do not follows the example I give above/temporal order).

This looks like when someone make a temporal error while typing “the” (as “teh”)).

Remember that since APFS, the sort order of FolderItems in a directory is not a given. If you want the FolderItems to be sorted alphabetically, you will need to do so after loading them into an array.

Hi Tim,

I’m an oldster, so, no APFS here (on El Capitan :wink: ).

Can it be confirmed that code in a button is executed line after line (I cannot believe it can be otherwise)…

PS: the generated images are very small and so all images appears nearly at the same time in the saved folder. I do not talk about I saw the files created in strange order; they are in the same row, stored in alphabetical order (most of the time.

BTW: in macOS 6/7 time frame (around 1988), we had a trick to alphabetize the order of the files in a folder. s this trick still working on APFS (Intel and M1) volumes ?

macOS X uses its own algorithm to alphabetize listings
they mostly make sense
until they dont
numbers as suffixes on names can mess with that ordering whn you start getting multiple digits added on as its not strictly lexical any more

There was a more detailed explanation either somewhere else here or on Discord…
I had a few hundred files that had Hex values (file$1B etc), and they did not sort in alphabetical order

Below are the used images names:

Completist.png
Cover.png
Folder_Bkgnd.png
Icon.png
Windows.png

There is no reason that can explain 'cause these are not fancy names (no leading numbers, only ASCII characters).

And they are stored in folder that is nested in Folders that are in Documents.

Yeah I recall that post as well
I think that was on Discord

EDIT: there is this


It may still apply

Emile? is that the order they are returned? If so, whats wrong with it? it is Alphabetical

Dave:
That was the correct order.

I just get a wrong order:
Cover.png
Folder_Bkgnd.png
Icon.png
Completist.png
Windows.png

Completist.png have to be first not where it is above.

I forgot to mention the folder where these appears is in Icon view (in the standard Finder, 128 pixels wide icon view, nothing fancy).

It is a real mystery.

Remember:
El Capitan / MacBook Pro Retina mid 2014.

PS: I hope you had a nice Christmas evening.

Nothing promises that files are stored and/or retrieved in any given order, neither alphabetical or even the order in which they were created. It is entirely the “choice” of the OS, and might not even be the same between any two operating systems.

So, once in a while macOS is crazy, then he’s back to normal ?

In the very same subject (resizing images to the same size), years ago I discovered that if I always want to get the same resize (I forgot if that was the width or the height fixed resize) of different sized images, I had to use Doubles instead of Integers (according to the docs, you have to use Integers).

On a different subject: I had hard times years ago with the xojo caches until I cleared them:
at my mrning desk, the project worked fine (sometimes after hard times in debug) to fail after a reboot at home. Then a Clear cache was added into the IDE. Now (on TOF), sometimes people complain about Xojo IDE strange ways; but because they do not read the documentation nor check the preferences, they do not clear the caches. (a phantom - removed - code runs until the developer quit Xojo, then reboot and re-run…)

Conclusion: for me it is still a mystery, but like many others, I will have to live with it.

This is the most often order of appearance of the files. (the order of appearance of the files once created; I do not say they will stay like that after one or many reboots / folder successive closes and opens)

The wong order appears once more. This time I tried some combinations applied on the original file and noticed some … differences:

a. sometimes (odd - even sized) the image is centered differently on screen (vs even - even sized) and the result order is different (how can these be related ? I take the loaded data to resize it, not the displayed canvas).

b. I made many times the resize with the same window, then tried after closing and opening the window. I do not noticed changes.

Obviously, I have to check my resize function, and once done, I have to take time to achieve a real debug session.

Emile… There is no “wrong order”… There is only an order that you don’t want.
If you want the files in a specific order, then YOU have to sort them yourself
The operating system will not guarantee the return order, macOS may differ from Win, FAT may differ from AFPS etc. etc…

File sizes (especially graphics) may not update quickly (especially in Finder). So you might change the file size, and Finder wont say it changed for a while but in fact the actual file size internally is correct.

2 Likes

OK.

But if I create folders in one displaying as Icon view with enough rooms to place 5 folders in a row, they always (AFAIK and excepting M1, and post High Sierra) appears in the order of creation.

Of course, I wrote the creation code in Xojo to save the files in a certain order. unlike Windows XP who never displayed my icons at the same place day after day, usually, the files “never” moves by themselves between boots or folder opening (else it is a bug).

Now, nobody knows, I have to move and try to think at fomething else (dinner ?).

Cheers

you say “display” as in Finder? or when you read them?

Finder sorts things… if you read them YOU need to sort

Display in an open and frontmost folder.

I never talk about read files in some order, it is only about saved time.

I drag an image from an open folder (Finder, view by Icon) and in the application front window, I click in a Process PushButton where the files are saved in a certain order. The icons does not always appears - in the open Finder folder - in the same order; mst of the time, not always.

Sorry if I was not crystal clear.

We can ask Finder to sort things, I do not do that in that case.
Finder sort things if the folder is displayed as list, but this is not the case.

Finder does what Finder does… if you do not tell it to apply a specific sort order, then it does what IT wants to do…

“IT” is back (from some horror movies)… :wink:

Thanks.