edman747 Posted February 5, 2007 Posted February 5, 2007 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 arestored a dictionary where the base file name characters are stored in strBase as a key andif 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 2hoteland 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 somelogic to handle special case names.would anyone be willing to suggest a better way of doing this? TIAhere 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 strOutputFor 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 NextNext ' 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 ifEnd Sub
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now