hello, thanks for your help. here is the near final vbscript. it still has a little trouble with some filename series projectg, projectg1 ... project8 does not get the nonnumber one first.
tweaked the regex to better split the filenames into character / number parts. found and online regex tester that helped.
it is updated to sort the dictionary by the key. and when an item is a number it sorts the rest of the items as numbers.
had to include special case stuf to handle names starting with numbers and names that are one number.
if anyone is real smart with vbscript. have a look. if not maybe something here will help you. thanks.
[code][codebox]Option Explicit
Dim objFSO
Dim ofolder
Dim objStream
Dim objStream2
Dim intCounter
Dim arrTestNames ()
Dim dicBaseNames
Dim strBase
Dim strName
Dim strNumber
Dim nUBound
Dim arrTemp
Dim strOutput, a
Const dictKey = 1
Const dictItem = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
'create the output file
Set objStream = objFSO.CreateTextFile("search3.log", True)
CheckFolder (objFSO.GetFolder(".")), objStream
ReDim Preserve arrTestNames (intCounter)
FillArray(objFSO.GetFolder(".")), objStream, arrTestNames
Const TextCompare = 1
'Start by making a dictionary of all the base names. The value will be an array of the numerals
Set dicBaseNames = CreateObject("Scripting.Dictionary")
dicBaseNames.CompareMode = TextCompare
For Each strName In arrTestNames
strBase = GetBaseName(strName)
strNumber = GetSequenceNumber(strName)
'workaround for single number names.
If strbase = "1" Then
strbase = "jam"
strNumber = "1"
End If
If strbase = "2" Then
strbase = "jam"
strNumber = "2"
End If
If strbase = "3" Then
strbase = "jam"
strNumber = "3"
End If
If strbase = "4" Then
strbase = "jam"
strNumber = "4"
End If
If strbase = "5" Then
strbase = "jam"
strNumber = "5"
End If
If strbase = "6" Then
strbase = "jam"
strNumber = "6"
End If
If dicBaseNames.Exists(strBase) Then
nUBound = UBound(dicBaseNames(strBase)) + 1
arrTemp = dicBaseNames(strBase)
ReDim Preserve arrTemp(nUBound)
arrTemp(nUBound) = strNumber
dicBaseNames(strBase) = arrTemp
Else
dicBaseNames.Add strBase, Array(strNumber)
End If
Next
set dicbasenames = SortDictionary(dicBaseNames, dictKey)
'set dicbasenames = sortdict(dicbasenames,objFSO.getfolder("."), objStream)
'step through the dictionary using basenames and numbers to update config files.
StepThruDic(objFSO.GetFolder(".")), objStream
MsgBox "Series Map Search Completed." + vbCr + "Please check updated map.cfg's." + vbCr + "See search.log for details " + CStr(Date)
Function SortDictionary(ByVal objDict, intSort)
' declare our variables
Dim strDict()
Dim arrTmp()
Dim objKey
Dim strKey, strItem
Dim X, Y, Z, i, j, temp
' get the dictionary count
Z = objDict.Count
' we need more than one item to warrant sorting
If Z > 1 Then
' create an array to store dictionary information
ReDim strDict(Z, 2)
X = 0
' populate the string array
For Each objKey In objDict
ReDim arrTmp(UBound(objdict(objkey)))
For i = 0 To UBound(objdict(objkey)) '- 1
arrTmp(i) = objDict.Item(objKey)(i)
Next
For i = UBound(objdict(objkey)) - 1 To 0 step -1
For j = 0 To i
If objKey <> "c" Then
If Len(arrTmp(j)) <> 0 And Len(arrTmp(j + 1)) <> 0 Then
If IsNumeric(arrTmp(j)) And IsNumeric(arrTmp(j + 1)) Then
If CInt(arrTmp(j)) > CInt(arrTmp(j + 1)) Then
Wscript.Echo CStr(Join(arrTmp))
temp = arrTmp(j + 1)
arrTmp(j + 1) = arrTmp(j)
arrTmp(j) = temp
End If
End If
End If
End If
Next
Next
strDict(X, dictKey) = CStr(objKey)
strDict(X, dictItem) = CStr(Join(arrTmp))
X = X + 1
Next
' perform a a shell sort of the string array
For X = 0 To (Z - 2)
For Y = X To (Z - 1)
If StrComp(strDict(X, intSort), strDict(Y, intSort), vbTextCompare) > 0 Then
strKey = strDict(X, dictKey)
strItem = strDict(X, dictItem)
strDict(X, dictKey) = strDict(Y, dictKey)
strDict(X, dictItem) = strDict(Y, dictItem)
strDict(Y, dictKey) = strKey
strDict(Y, dictItem) = strItem
End If
Next
Next
' erase the contents of the dictionary object
objDict.RemoveAll
' repopulate the dictionary with the sorted information
For X = 0 To (Z - 1)
objDict.Add strDict(X, dictKey), Split(strDict(X, dictItem))
Next
End If
Set SortDictionary = objDict
End Function
Function GetSequenceNumber(strName)
Dim oRE
Dim colMatches
Dim oMatch, I
Set oRE = New Regexp
'oRE.Pattern = "\D*(\d*)(.*$)"
oRE.Pattern = "[^\D]*\D*(\d*.*$)"
oRE.IgnoreCase = True
Set colMatches = oRE.Execute(strName)
If colMatches.Count > 0 Then
Set omatch = colMatches(0)
If oMatch.SubMatches.Count > 0 Then
For I = 0 To oMatch.SubMatches.Count -1
GetSequenceNumber = GetSequenceNumber & oMatch.SubMatches(I)
Next
End If
Else
GetSequenceNumber = ""
End If
'For Each oMatch In colMatches
' GetSequenceNumber = oMatch.SubMatches(0) & oMatch.SubMatches(1)
' Exit Function
'Next
'GetSequenceNumber = ""
End Function
Function GetBaseName(strName)
Dim oRE
Dim colMatches
Dim oMatch, I
Set oRE = New Regexp
'oRE.Pattern = "(\D*)\d*"
oRE.Pattern = "^(\d*\D*)\d*"
oRE.IgnoreCase = True
Set colMatches = oRE.Execute(strName)
If colMatches.Count > 0 Then
Set oMatch = colMatches(0)
If oMatch.Submatches.Count > 0 Then
For I = 0 To oMatch.SubMatches.Count -1
GetBaseName = GetBaseName & oMatch.SubMatches(I)
Next
End If
End If
'For Each oMatch In colMatches
' GetBaseName = oMatch.SubMatches(0)
' Exit Function
'Next
'GetBaseName = "ERROR"
End Function
Sub CheckFolder(objCurrentFolder, objLogFile)
Dim strTemp
Dim strSearch
Dim strOutput
Dim objNewFolder
Dim objFile
Dim objStream
Dim a
strSearch = ".bsp"
For Each objFile In objCurrentFolder.Files
strTemp = Right(objFile.Name, 4)
If UCase(strTemp) = UCase(strSearch) Then
intCounter = intCounter + 1
End If
Next
End Sub
Sub FillArray(objCurrentFolder, objLogFile, arrTestNames)
Dim strTemp
Dim strSearch
Dim strOutput
Dim objNewFolder
Dim objFile
Dim objStream
Dim a
Dim intIndex
strSearch = ".bsp"
intIndex = 0
For Each objFile In objCurrentFolder.Files
strTemp = Right(objFile.Name, 4)
If UCase(strTemp) = UCase(strSearch) Then
arrTestNames (intIndex) = Split(objFile.Name, ".")(0)
intIndex = intIndex + 1
End If
Next
End Sub
Sub StepThruDic(objCurrentFolder, objLogFile)
Dim strTemp
Dim strSearch
Dim strOutput
Dim objNewFolder
Dim objFile
Dim objStream
Dim i, j, temp, num1, num2
Dim strNextmap
strOutput = "changelevel bug squished. Summary of changes:"
objLogFile.WriteLine strOutput
For Each strBase in dicBaseNames.Keys
For i = 0 To UBound(dicBaseNames(strBase)) - 1
If strbase = "jam" Then
strOutput = dicBaseNames(strBase)(i) & ".cfg"
objLogFile.WriteLine strOutput
strOutput = " nextmap " & dicBaseNames(strBase)(i + 1)
objLogFile.WriteLine strOutput
'update the config file.
If objFSO.FileExists(dicBaseNames(strBase)(i) & ".cfg") Then
objFSO.OpenTextFile(dicBaseNames(strBase)(i) & ".cfg", 8).WriteLine _
vbCrLf & "nextmap " & dicBaseNames(strBase)(i + 1)
Else
'create the config file.
strTemp = dicBaseNames(strBase)(i) & ".cfg"
Set objStream = objFSO.CreateTextFile(strTemp, True)
objStream.WriteLine _
"nextmap " & dicBaseNames(strBase)(i + 1)
End If
Else
'skip c1,c2,c3 series, blank records, special case
If strBase <> "c" _
And "nextmap " & strbase & dicBaseNames(strBase)(i) <> "nextmap " Then
strNextmap = strbase & dicBaseNames(strBase)(i + 1)
If strBase & dicBaseNames(strBase)(i) = "assaultmesa2-2" Then
strOutput = strBase & dicBaseNames(strBase)(i + 1) & ".cfg"
objLogFile.WriteLine strOutput
strOutput = " nextmap " & strBase & dicBaseNames(strBase)(i)
objLogFile.WriteLine strOutput
If objFSO.FileExists(strBase & dicBaseNames(strBase)(i + 1) & ".cfg") Then
objFSO.OpenTextFile(strBase & dicBaseNames(strBase)(i + 1) & ".cfg", 8).WriteLine _
vbCrLf & "nextmap " & strbase & dicBaseNames(strBase)(i)
End If
Else
' write to the search log.
strOutput = strBase & dicBaseNames(strBase)(i) & ".cfg"
objLogFile.WriteLine strOutput
strOutput = " nextmap " & strNextmap
objLogFile.WriteLine strOutput
'update the config file.
If objFSO.FileExists(strBase & dicBaseNames(strBase)(i) & ".cfg") Then
objFSO.OpenTextFile(strBase & dicBaseNames(strBase)(i) & ".cfg", 8).WriteLine _
vbCrLf & "nextmap " & strbase & dicBaseNames(strBase)(i + 1)
Else
'create the config file.
strTemp = strBase & dicBaseNames(strBase)(i) & ".cfg"
Set objStream = objFSO.CreateTextFile(strTemp, True)
objStream.WriteLine _
"nextmap" & " " & strbase & dicBaseNames(strBase)(i + 1)
End If
End If
End If
End If
Next
Next
End Sub[/code][/codebox]