Jump to content

Recommended Posts

Posted

I have a script that processes a list of file names. if there is a pattern in the file names that indicates a series of related names.

the script updates the associated configuration file with the name of the next file in the series and writes an entry in a log.

the file names are read from a directory and striped of the file extension then the names are

stored a dictionary where the base file name characters are stored in strBase as a key and

if there is a number, the number and the rest of the line are stored in strNumber as an array of string.

simple file names like map1, map2, map3. strBase = map, strNumber(0) = 1, strNumber(1) = 2 ...

and a series like: escape2_a, escape2_b, escape2_c. work just fine.

problem: a series of names like 1, 2, 3 are interrupted by single (non-series) names like 2hotel

and series names like assaultmesa2, assaultmesa2-2 get inverted?

with no formal file naming convention or input into individual users choice of file names.

I made the following assumption: a series of names can be one or more char optionally followed by one or more numbers.

every time there is a special case that does not match. I have to keep changing the script to include some

logic to handle special case names.

would anyone be willing to suggest a better way of doing this? TIA

here is the output subroutine.

Sub StepThruDic(objCurrentFolder, objLogFile)

Dim strTemp
Dim strSearch
Dim strOutput
Dim objNewFolder
Dim objFile
Dim objStream
Dim i
Dim strNextmap

strOutput = "changelevel bug squished. Summary of changes:"
objLogFile.writeline strOutput
For Each strBase in dicBaseNames.Keys
For i = 1 To UBound(dicBaseNames(strBase))
'skip c1,c2,c3 series, blank records, special case strbase is a number or starts with a number.
If strBase <> "c" _
and "nextmap " & strbase & dicBaseNames(strBase)(i) <> "nextmap " _
and dicBaseNames(strBase)(i - 1) <> "2hotel" _
and dicBaseNames(strBase)(i - 1) <> "2battle" then
strNextmap = strbase & dicBaseNames(strBase)(i)
If Len(strBase) = 0 and dicBaseNames(strBase)(i - 1) = "2" then
strNextmap = "3"
End If

' write to the search log.
strOutput = strBase & dicBaseNames(strBase)(i - 1) & ".cfg"
objLogFile.writeline strOutput
strOutput = " nextmap " & strNextmap
objLogFile.writeline strOutput

' update the config file.
If objFSO.FileExists(strBase & dicBaseNames(strBase)(i - 1) & ".cfg") Then
objFSO.OpenTextFile(strBase & dicBaseNames(strBase)(i - 1) & ".cfg", 8).WriteLine _
vbCR & vbLF & "nextmap " & strbase & dicBaseNames(strBase)(i)
Else
'create the config file.
strTemp = strBase & dicBaseNames(strBase)(i - 1) & ".cfg"
Set objStream = objFSO.createtextfile(strTemp, True)
objStream.WriteLine _
"nextmap" & " " & strbase & dicBaseNames(strBase)(i)
End If
End If
Next
Next
' in the odd case when series sequence cannot be determined by mapname.
' begin to rip the ent data and search for trigger_changelevel or map string
' if strBase & dicBaseNames(strBase)(i) = "c1a0" or "c1a0d" then
' Dim Act : Set Act = CreateObject("Wscript.Shell")
' Act.Run("cmd.exe /c ripent.exe -export " & strBase & dicBaseNames(strBase)(i)),1,True
' search for unique string "map" get the name.
' test for more than one occurrence of "map" take the second one.
' end if

End Sub


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...