How macOS Parent Folder Item Indexes Created?

I added a bunch of empty subfolders to a parent folder. Most use a unique single character as their name (including a space). I duplicated several folders in the Finder using Command + D.

The subfolders are sorted by name in the Mac Finder as shown in the left column of the images.

The right column shows the names of the folders as obtained with a loop using the parent folder’s index value.

This has the appearance of the parent using a file index based upon an array of sub arrays.

The sub arrays are based upon the first character of the file and are sorted alphabetically.

The sub arrays are sorted alphabetically. The main array is not sorted alphabetically but according to a hierarchy established by Apple for unknown reasons.

If I create five folders starting with these five characters in any parent folder they will always be returned in this order via the index property.

[space ] Index 1
! Index 2
" Index 3

Index 4

$ Index 5

If I duplicate the folder named " its now has the index of 4.

Files beginning with a space are one sub array while those beginning with a ! are another sub area. The space sub array is always first followed by the sub array for ! and so on.

[space ] Index 1
! Index 2
" Index 3
" copy Index 4

Index 5

$ Index 6

Is this how MacOS is creating folder indexes and why Xojo is returning such values?

This post indicates they used to be returned alphabetically before APFS.

Order of Folderitem.items

the INDEX is not something the OS creates
its simply a number to mean “the item at offset N” and if you were to delete one of those folders all those indexes could change

I would NOT rely on INDEX to mean any specific item - i would use a Folderitem for that

Yes, I understand the indexes will change if an item is removed as demonstrated by my example of adding a folder.

Why are the names of the subfolders always be returned in the same order using the index property of the parent folderitem?

If I manually create six sub folders using the following names in two or more parent folders they will always have the same index. It does not matter which parent folder they are in, how they are sorted in the Finder, when they were created, when they were modified or even what drive they they are on.

%
&

(
)
*

When I obtain file names from a parent folder using index why are they always be shown in the same order, with any files begging with a blank first followed by any files begging with a underline?

[code]Dim List as String
Dim Count, DoIt as Integer
Dim F, I as FolderItem

F = GetFolderItem(“Folder Names”)
Count = F.Count

If F.Exists and F <> Nil then

For DoIt = 1 to Count
  
  I = F.Item(DoIt)
  
  If I.Name <> ".DS_Store" then
    List = List + I.Name + EndOfLine
  End If
  
Next

End If

TextArea1.Text = List[/code]

I just manually created a new parent folder in the Finder. I then manually created subfolders named

[space]
&
+
~
c
j
k
m
z

If then create a new parent folder with a different name and manually create the above subfolders again in a different order.

The above code will always return the names in the order below. Why?

[space]
&
+
c
j
k
m
z
~

If I add a new folder named @ to both parent folders the order of subfolder names from both parent folders will now be.

[space]
&
+
@
c
j
k
m
z
~

[quote=467143:@Charles Greyson]Yes, I understand the indexes will change if an item is removed as demonstrated by my example of adding a folder.

Why are the names of the subfolders always be returned in the same order using the index property of the parent folderitem?
[/quote]

because however the folderitem grabs the list of items and iterates through them is consistent so from one time to the next you get items in the same “order” (whatever order that might be this can be OS dependent)

the order of CREATION has nothing to do with how the finder grabs the list

its why I said I would NOT rely on the INDEX for ANYTHING except maybe to iterate over the list

the INDEX isnt unique and does NOT uniquely identify a file in any way - its just a number

the FOLDERITEM that parent.child(index) gives you DOES