Sorting "Lookin" code

  • Thread starter Thread starter DP
  • Start date Start date
D

DP

2-3 years ago, someone helped me to adjust the code below by using - as I
recall - some kind of internal additional code (bubble array?) so that the
file names would be "read" in the exact order in which they show up in a
usual Windows Explorer or MyComputer window.

The problem is that my files are all numbers, like this:

5-1-5.tif
5-6-10.tif
etc.

When I have something like 5-11-15.tif

I end up in such cases with this kind of sort:

5-1-5.tif
5-11-15.tif
5-6-10.tif

The "second set" of digits after the first "x-" or, in this case, "5-1," are
page numbers of documents. This is why it's imperative that the files stay
in sequence, and the Lookin code by itself will not do this.

Can someone help me with some kind of internal - I believe it is - "bubble
array?"

Or some other approach?

Thank you, David Pike
_______________________
With fs
.lookin = "C:/xxxxxx/xxxxxx/"
.FileName = "*.tif"

If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
'MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
'MsgBox .FoundFiles(i)
il.LoadFromFile .FoundFiles(i), 0, 0, 1

Next i
Else
MsgBox "There were no files found."
End If
End With
 
Do you have these file names in a table?

If the file names are in a table..then it is a simple matter to sort the
data....

All you do is simply extract each number like:

C1:cint(split([FileName],"-")(0))
C2:cint(split([FileName],"-")(1))
C3:cint(split([FileName],"-")(2))


So, a query with the above expressions will then sort if you order by
c1,c2,c3
 
No, the date is not in a table - it is coming directly from the computer
directory, but you propose an interested solution. If I can't get
instructions for resorting the located files with some kind of redim
statement, I suppose I could always try reading the contents of the
directory into a table, and then using a query like the one you suggest to
sort the contents of the table the way they need to be sorted.

Thanks for the suggestion, David Pike
 
Well, then if you got a string of:

abc-def-hij
strMyString = "abc-def-hij"

Then

debug.print split(strMyString,"-")(0) gives abc
debug.print split(strMyString,"-")(1) gives def
debug.print split(strMyString,"-")(2) gives hij
 
Back
Top