--
[ Picked text/plain from multipart/alternative ]
hello all,
here is what I've got so far in a vbscript solution. a little broken when it
comes to the odd case hostage hostage2a hostage2b. and for opening the
correct file to append a line.
any help?
---code
Option Explicit
Dim objFSO
Dim ofolder
Dim objStream
Dim intCounter
Dim arrTestNames ()
Dim dicBaseNames
Dim strBase
Dim strName
Dim strNumber
Dim nUBound
Dim arrTemp
Dim strOutput
Set objFSO = CreateObject("Scripting.FileSystemObject")
'create the output file
Set objStream = objFSO.createtextfile("search.log", True)
CheckFolder (objFSO.getfolder(".")), objStream
ReDim Preserve arrTestNames (intCounter)
FillArray(objFSO.getfolder(".")), objStream, arrTestNames
'Start by making a dictionary of all the base names. The value will be an
array of the numerals
Set dicBaseNames = CreateObject("Scripting.Dictionary")
For Each strName In arrTestNames
strBase = GetBaseName(strName)
strNumber = GetSequenceNumber(strName)
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
'now step through the dictionary using basenames.
StepThruDic(objFSO.getfolder(".")), objStream
MsgBox "File Search Completed." + vbCr + "Please check search.log for
details."
Function GetSequenceNumber(strName)
Dim oRE
Dim colMatches
Dim oMatch
Set oRE = New Regexp
oRE.Pattern = "\D*(\d*)(\D*)"
oRE.IgnoreCase = True
Set colMatches = oRE.Execute(strName)
For Each oMatch In colMatches
GetSequenceNumber = oMatch.Submatches(0)
Exit Function
Next
GetSequenceNumber = ""
End Function
Function GetBaseName(strName)
Dim oRE
Dim colMatches
Dim oMatch
Set oRE = New Regexp
oRE.Pattern = "(\D*)\d*(\D*)"
oRE.IgnoreCase = True
Set colMatches = oRE.Execute(strName)
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
'Got one
'a=Split(CStr(objFile.Name),".")
intCounter = intCounter + 1
'strOutput = CStr(intCounter) & " " & a(0)
'objLogFile.writeline strOutput
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
'Got one
a=Split(CStr(objFile.Name),".")
'populate database
arrTestNames (intIndex) = a(0)
'strOutput = arrTestNames (intIndex)
'objLogFile.writeline strOutput
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 a
dim intIndex
dim strName2
dim strBase2
dim strNumber2
dim strName3
dim strBase3
dim strNumber3
dim i
For i = 0 to intCounter - 1
strName = arrTestNames(i)
strBase = GetBaseName(strName)
strNumber = GetSequenceNumber(strName)
If strNumber = "" Then
strName2 = arrTestNames(i + 1)
strBase2 = GetBaseName(strName2)
If StrComp(strBase2, strBase) = 0 Then
strNumber2 = GetSequenceNumber(strName2)
strOutput = "nextmap" & " " & strbase2 & strnumber2 & " " &
strname & ".cfg"
objLogFile.writeline strOutput
End If
If strNumber2 = "1" Then
strName3 = arrTestNames(i + 2)
strBase3 = GetBaseName(strName3)
If StrComp(strBase3, strBase) = 0 Then
strNumber3 = GetSequenceNumber(strName3)
strOutput = "nextmap" & " " & strbase3 & strnumber3 & " " &
strname2 & ".cfg"
objLogFile.writeline strOutput
End If
End If
End If
If strNumber = "1" Then
strName2 = arrTestNames(i + 1)
strBase2 = GetBaseName(strName2)
If StrComp(strBase2, strBase) = 0 Then
strNumber2 = GetSequenceNumber(strName2)
strOutput = "nextmap" & " " & strbase2 & strnumber2 & " " &
strname & ".cfg"
objLogFile.writeline strOutput
End If
If strNumber2 = "2" Then
strName3 = arrTestNames(i + 2)
strBase3 = GetBaseName(strName3)
If StrComp(strBase3, strBase) = 0 Then
strNumber3 = GetSequenceNumber(strName3)
strOutput = "nextmap" & " " & strbase3 & strnumber3 & " " &
strname2 & ".cfg"
objLogFile.writeline strOutput
End If
End If
End If
Next
End Sub
thanks
On 1/22/07, ed miller <[EMAIL PROTECTED]> wrote:
>
> hello Dan, thanks for your reply.
> the changelevel bug is on listening servers.
>
> here is what I've got in a batch script.
> @echo off
> setlocal enabledelayedexpansion
> if exist filenames.txt del filenames.txt
> for %%x in (*.bsp) do echo %%x >>filenames.txt
> for /f "tokens=* delims=" %%a in (filenames.txt) do (
> set txtline=%%a
> set txtline=!txtline:.bsp=!
> echo !txtline!>>tmp.txt)
> del filenames.txt & ren tmp.txt filenames.txt
> endlocal
>
> reads file names from a directory into a text file strips off the file
> name extension.
> I don't know how to compare the file names or do sub string manipulation.
> maybe it cannot be done in a batch script.
> anyone have vbscript experience?
>
>
--
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders