f.Count = 0 but there are files in that directory!

The à in question have been typed from the keyboard in the Finder.
Now I tried `+a (still in the Finder) that makes a ‘à’ just in case it is translated as UTF-8 (or not). I ran the project and no change, still not the problem.

Back to the UTF proposal:

all folder names have been typed in the Finder…
if we cannot have confidence with what we type from the keyboard, same computer/OS conditions (different results depending on the application)…

“Confidence is dead, DT killed it.”
Old Kongzi tellings.

As I say..

The sortwith() solution would avoid future issues like this, because instead of referring to a file later using its name (which may have changed if the encoding is slightly incorrect),
you can go straight to the folderitem itself.

Sorry Jeff, but I do not get it.

As far asI understand, a Gremlin character was in a folder name; it is not a Sort trouble.
That said, I understand what you wriote, but not the SortWith example from the documentation. The example says:

' Assume there is an array called People() As Person that contains
' a collection of Person objects

a. The doc does not says what these objects [people() Array] are.
b. The doc does not explain how that works, but once dot a is explained we can implement the code and watch the result (and probably understand how it works if needed then).

I am walking beside my shoes, sorry :frowning:

Also: there is not a single diacritic character in all example.
USA: 340,000,000 of human being,
Workd: 8, 000, 000, 000,000 of human being.

Hey Xojo, wake up !

you get a list of the folder names by asking each folderitem what the file name is?
You sort that array
Then you try to access the folders using the name which is in the array.
But we seem to have shown that some of those names are no longer the same once they are in a Xojo string.

Using an array of folderitems means you are talking to the actual folder item, not creating one using a string.
You can sort the array of folderitems by using sortwith, which sorts them based on the filenames.
Even if the characters have been changed, the sort still happens.

2 Likes

I guess you have a folder full of content used by your application that makes sense when seen using your application. So the folder name in the tree as “a title” is not necessary, not even desired as a design to avoid such Gremlins things.

Let’s say you have currently a root folder like “publications”, and 2 folders under it called: “La sorcière de la rue mouffetard” and “La chèvre de Monsieur Seguin” like:

Publications:
              La sorcière de la rue mouffetard
              La chèvre de Monsieur Seguin

Each of those folders has a lot of cont that makes sense to your application, let’s say some default names as front.jpg, back.jpg, summary.txt … let’s call them a “book data” that for some important reason you opted to organize this way instead of using a database. You should move the language barrier from the structures to your data. No accents in the folders and files.
How to do that?
Add a new entity to your collection, as a file called title.txt, and use a simple folder name for a book data.
So in your previous tree design you had:

Publications:
              La sorcière de la rue mouffetard:
                                               front.jpg
                                               back.jpg
                                               summary.txt
              La chèvre de Monsieur Seguin:
                                               front.jpg
                                               back.jpg
                                               summary.txt

Now you have:

publications:
              0000000001:
                          title.txt
                          front.jpg
                          back.jpg
                          summary.txt
              0000000002:
                          title.txt
                          front.jpg
                          back.jpg
                          summary.txt

If you read publications/0000000001/title.txt you will see “La sorcière de la rue mouffetard” as it was typed and expected by your app. The same for publications/0000000002/title.txt and “La chèvre de Monsieur Seguin”

At some point you app can scan this structure and feed a database, from there you can sort data, search, etc.

PS. All Rick’s thoughts and writings here, no AI. Seems like I need to say that from time to time.

PS2: In a DB you could store the original name and a version of it removing all accents, and use that version to sort or whatever, as: original:“La chèvre de Monsieur Seguin”, neutral:“La chevre de Monsieur Seguin”

2 Likes

There are not 8 trillion people in the world.

As far as I understand, a Gremlin character was in a folder name; it is not a Sort trouble.

But you stop knowing what the folder is ACTUALLY called when you put the names into an array and sort it.

What is in this sorted array are strings which may no longer match the names of the folders.
So if you create a folderitem from the array, you get an invalid item.

Using Rick’s examples

You find the names of all the folders in “some place”
They are

La sorcière de la rue mouffetard
La chèvre de Monsieur Seguin

Something happens to these names when you read them - incorrect encoding, who knows, but what goes into the array is

La sorcière de la rue mouffetard
La chėvre de Monsieur Seguin //note I changed the diacritical here visually

You sort this, and you get

La chėvre de Monsieur Seguin
La sorcière de la rue mouffetard

Now, you work through this list alphabetically.
When you say

dim f as folderitem = Comics_folder.child (Page_Names(0))

You get a folderitem that is invalid because it is using the wrong name.
But if you sorted an array of folderitems, you would be able to say

for x as integer = 0 to folderitems.lastindex
dim f as folderitem = folderitems(x)
//use it

and that would work because the folderitem itself is still pointing to the actual folderitem you found.

I understand that you are confused by SortWith. It’s hard to follow.
Maybe look at the other sorting method

You create this method

function SortbyFileNames(a as folderitem,b as folderitem)
  If a.filename  > b.filename  Then Return 1
  If a.filename  > b.filename  Then Return -1
   Return 0
end function

And sort the array of folderitems with

Folderitems.sort (AddressOf SortbyFileNames)

All: thank you for your answers.

I am not sure I understand everything, but I better understand after reading your answers.

@Robert_Livingston:
This proves I am really tired: I counted the number of zeroes, but failed.
Thanks for correct me.

In the past (another project), I used this trick, but I found (then) useless / time wasting to create a list when I can directly deal with the Master Folder full of data. It worked then without trouble (around REALbasic 5 I think…)