Getting files alphabetically from a folder

At last, it is my time to have troubles wth the file stored order.

My Method, tested on a friend computer, returns the Table of Contents in no order; say pages 2, 3, 12, 44, 1, 38 and so on.

I do cannot checked that right now, but here’s my idea:

At source folder drop time, I will load all files descriptors for all items in the source folder, sort then alphabetically based on their names and do the job from there.

Your opinion ?

PS: always think different they says. So, I created a brand new folder, then I moved the files by alphabetical order to that new folder and pass that folder into my method: I get the results in the same (bad) order.

I am curious to know how - internally - the file manager works.

Doh: I have a brilliant idea: what if I return the files randomly ? Oh, yes ! It will be fun to code that ! (there is irony in that sentence).

Put the names in one array, a reference to their FolderItems in another array, then SortWith.

Thank you Anthony for the tip, but I do not get it. What is the relation between the two arrays ?

PS that’s a fast answer !

I’m not sure I understand your question, but consider these two arrays as they might be loaded from the filesystem:

 ______________________
| Array 1 | Array 2    |
| Finame  | FolderItem |
|----------------------|
|       2 | 2.txt      |
|       4 | 4.txt      |
|       1 | 1.txt      |
|       3 | 3.txt      |
'----------------------`

Now, that’s how they might appear if you populate Array1 using the extracted filename without extension at load time and place its corresponding FolderItem into Array2. If you then want the references to be numerically in order, you can do the following:

'// The next two lines are illustrative only
Array1 = Array( 2, 4, 1, 3)
Array2 = Array("2.txt", "4.txt", "1.txt", "3.txt")
Array1.SortWith(Array2)

Which should yield:

 ______________________
| Array 1 | Array 2    |
| Finame  | FolderItem |
|----------------------|
|       1 | 1.txt      |
|       2 | 2.txt      |
|       3 | 3.txt      |
|       4 | 4.txt      |
'----------------------`

You can then reliably iterate over Array2.

OK, what you wrote above is new for me, that is why I do not understand previously.

I have the reference of the “master“ folder, all I have to do is store the file names in an array, sort it, then build a reference .TrueChild("") and deal with all items in the Array.

Actually, I drop a folder on a Canvas, then I iterate Obj.FolderItem.TrueItem(Loop_Idx).

What I wrote above is simple and somewhere looks like what you wrote.

You can read up on SortWith here.

Thanks.

Not tested, but here’s some code:

  Dim Items_Arr() As String
  Dim Itm_Idx     As Integer
  Dim Itm_Cnt     As Integer
  
  Itm_Cnt = Folder_FI.Count
  
  For Itm_Idx = 1 To Itm_Cnt
    Items_Arr.Append Folder_FI.TrueItem(Itm_Idx).Name
    
    If UserCancelled Then Exit
  Next
  
  Items_Arr.Sort
  
  // Then I scan the Array and - I forget: I only needed the items names…

It works here so it will certainly there (where it is needed).

The other change to my earlier code is:

Was:

Item_FI = Folder_FI.TrueItem(Loop_Idx) // Folder_FI reference the dropped folder

Now:

Item_FI = Folder_FI.TrueChild(Items_Arr(Loop_Idx))

… and I forgot that I only need the item name. I will change that. But for other’s reference this is good (I hope).

That works fine (I had to change the loop 0 to Item_Cnt - 1 in my code).

I forgot how AirDrop is fine !

I get it.

I do not understand earlier because in my case, there is nothing to place in the first array (and then my mind was far away the proposed solution)
.
I set, in magazine scanned jped file names, informations about the magazine Table Of Contents. So, basically, there is no pattern to follow (excepted pages &, 2 and 3; worst, the number of pages may vary°.

So, I cannot apply a pattern in an Array.

What saves me is the way the files are named:

Mirror 25 - 01 - Cover photo by Albert Chame (14th Century).jpg
Mirror 25 - 02 - Table of Contents - Advertising for Saint Gobain
Mirror 25 - 03 - Silver or Aluminum ? What’s the best process ?

Mirror 25: is the magazine name and issue number;
01 thru 03 are the pages numbers.

The other pages numbers are where they will be depending on the article length, of course / as in each and every magazines.

A simple alphabetization sort is enough.

Then the extraction method can do its job easilly and report the magazine contents in the correct order.

Is it clear now ?

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.