I am using the following vbs to read the JPG images in a directory:
Set objFolder = objFso.GetFolder(objShell.CurrentDirectory)
Set TifCollection = CreateObject("Scripting.Dictionary")
For Each objFile In objFolder.Files
If objFso.GetExtensionName (objFile.Path) = "jpg" Then
file = Split(objFile.Name, "_")(0)
page = Split(objFile.Name, "_")(1)
If Not TifCollection.Exists(file) Then
TifCollection.Add file, CreateObject("Scripting.Dictionary")
End If
TifCollection.Item(file).Add page, ""
End If
Next
For example directory contents:
image-00003844_1.jpg
image-00003844_2.jpg
image-00003844_3.jpg
...
image-00003844_10.jpg
The problem now is that the array TifCollection
I create, is sorted as follows:
image-00003844_1.jpg
image-00003844_10.jpg
image-00003844_2.jpg
image-00003844_3.jpg
...
image-00003844_9.jpg
In other words, image 10
follows image 1
because, i assume, the array is sorted alphabetically (?)
When I later loop through the array though, I need the correct numerical order:
image-00003844_1.jpg
image-00003844_2.jpg
...
image-00003844_10.jpg
How can i re-order the array?
---- EDIT - FULL CODE
-----
Set objShell = CreateObject("WScript.Shell")
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(objShell.CurrentDirectory)
Set TifCollection = CreateObject("Scripting.Dictionary")
Set objLines = CreateObject("Scripting.Dictionary")
' Compile 2-dimensional array listing all documents with their pages
For Each objFile In objFolder.Files
If objFso.GetExtensionName (objFile.Path) = "jpg" Then
file = Split(objFile.Name, "_")(0)
page = Split(objFile.Name, "_")(1)
If Not TifCollection.Exists(file) Then
TifCollection.Add file, CreateObject("Scripting.Dictionary")
End If
TifCollection.Item(file).Add page, ""
End If
Next
funcSortKeysByLengthDesc(TifCollection)
' Loop through the array to compile the loadfile
For Each file In TifCollection.Keys
For Each page In TifCollection(file)
If (page = "1.jpg") Then
objLines.Add file & ",," & file & "_" & page & ",Y,,," & TifCollection(file).Count, ""
Else
objLines.Add file & ",," & file & "_" & page & ",,,,", ""
End If
Next
Next
' Write to filesystem
strFileName = year(date) & month(date) & day(date) & hour(time) & minute(time) & second(time) & "-" & objLines.Count & "-IMAGES.opt"
Set objLoadfile = objFso.CreateTextFile(objFolder & "\" & strFileName,True)
objLoadfile.Write(Join(objLines.Keys, VBCRLF))
Function funcSortKeysByLengthDesc(dctList As Object) As Object
'todo
End Function