Announcement

Collapse
No announcement yet.

batch or vbs help

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • batch or vbs help

    hello all,

    I want to write a script that is native to xp.
    The script will read a list of file names from a directory.
    strip off the file name extension. compare the root file name to the
    next file name in the list to determine if there is a sequence(123, abc).
    if there is a sequence, append one line to a text file.
    the root name of the text file is the same as the first one being examined.
    the line being appended will contain the root name of the next file in the sequence.

    recent steam(valve software's content delivery system)
    updates have uncovered a changelevel bug in svencoop3.0
    this bug prevents the server from automatically changing to the next map.
    it affects maps in a series like toonrun1.bsp toonrun2.bsp toonrun3.bsp

    a workaround is to put a nextmap statement in the map config file.
    ie. toonrun1.cfg would have this added: nextmap toonrun2

    I imagine this is fixed in svencoop3.5
    while waiting for the upcoming release of version 3.5 originally planned dec 04

    question for the community: is it possible to write a script that will edit the cfg files?
    dir *.bsp
    afrikakorps1.bsp
    afrikakorps2.bsp
    afrikakorps3.bsp
    auspices.bsp
    toonrun1.bsp
    toonrun2.bsp
    toonrun3.bsp
    hostage.bsp
    hostage2a.bsp
    hostage2b.bsp

    append a line to afrikakorps1.cfg like: nextmap afrikakorps2
    append a line to afrikakorps2.cfg like: nextmap afrikakorps3
    no change to afrikakorps3.cfg
    no change to auspices.cfg

    this will not fix the Half-Life single player maps in Sven Co-op3.0 as the correct sequence
    cannot be determined from the file names. it's OK I already fixed them.

    in a batch script I can read the map names and strip off the file extension
    it is easy to append a nextmap statement to a cfg file.
    but I don't know how to manipulate the strings.

    this may only affect a couple of hundred maps on a couple of hundred computers
    someone said it would be easy to do in perl or python but that would require
    anyone wanting to use the script to install support for perl or python.
    vbs is native to xp but I don't know anything about it.

    maybe easy to do in mawk, then compile to win32 exe using awka
    but then I would have to give scary exe files to other users.

    any help I would be eternally grateful.

  • #2
    Re: batch or vbs help

    You are all over the map in this post. If you'd like to know how to search a directory or how to do some substring testing / manipulation, ask us for that. It appears you are looking for a turn-key solution.

    This doesn't look like a difficult problem but, I'm not prone to coding an application without a purchase order.

    You really need to contract w/ your VBS person for a day or two of work.

    EDIT -- Also, don't get all over the map on technologies. VBS is well suited for this task. Unless you're a big Perl / Python / ??? shop, I'd stick w/ Microsoft -- did I just say that out load ?!?!?
    Last edited by rvalstar; 22nd January 2007, 23:04.
    Cheers,

    Rick

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

    Comment


    • #3
      Re: batch or vbs help

      Thank you Rick.

      here is what I've got.
      @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 text file. strips off the file name extension.
      I don't know how to compare the file names or
      do sub string manipulation.

      Comment


      • #4
        Re: batch or vbs help

        Yep, CMD files have their limitations. You may need to go to a VBS for this one. Any VBS experience on your site?
        Cheers,

        Rick

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

        Comment


        • #5
          Re: batch or vbs help

          Hello Rick, thanks for your reply.

          maybe it cannot be done a batch script.
          I have no vbs experience. have posted on the mods fourms. no one there has vbs experience.

          Comment


          • #6
            Re: batch or vbs help

            Originally posted by edman747 View Post
            Hello Rick, thanks for your reply.

            maybe it cannot be done a batch script.
            I have no vbs experience. have posted on the mods fourms. no one there has vbs experience.
            I recently wrote a vbs that will enumerate a directory for moving files based on age. You can probably use part of this code to do the same with the bsp files.
            http://forums.petri.com/showthread.php?t=12486

            From there...

            You'll then need some way of determining a repeating pattern to filenames - this imo is the hardest part. Seach Google to get an idea of what you're undertaking.

            Opening the cfg assuming it's plain text and appending a line to the end of it is very simple. Get the other stuff out of the way first.
            Last edited by ahinson; 23rd January 2007, 06:10.
            Andrew

            ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

            Comment


            • #7
              Re: batch or vbs help

              thank you for your reply. here I attempt to describe the problem differently.
              map names are sequential. typically map1 map2 map3, sometimes map map2a map2b map3
              made up of a mapname and an extension or modifier as the number and everything following it.
              ie. map2a is mapname = map plus a modifier = 2a
              mapnames.txt is sorted directory listing of map names with the .bsp extension stripped.

              read a line from mapnames.txt
              mapname = line
              process mapname one character at a time
              if a number is found save the number and everything after it.
              modifier = "whatever"
              no number found
              modifier = ""
              mapname = line - modifier

              read the nextline from mapnames.txt
              mapname2 = line
              process mapname2 one character at a time
              if a number is found save the number and everything after it.
              modifier2 = "whatever"
              no number found
              modifier2 = ""
              mapname2 = line - modifier2

              if mapname is like mapname2
              append one line of text to the file: mapname + modifier + .cfg
              the line would be: nextmap mapname + modifier2

              read the nextline from mapnames.txt
              mapname3 = line
              process mapname3 one character at a time
              if a number is found save the number and everything after it.
              modifier3 = "whatever"
              no number found
              modifier3 = ""
              mapname3 = line - modifier3

              if mapname is like mapname3
              append one line of text to the file: mapname + modifier2 + .cfg
              the line would be: nextmap mapname + modifier3

              keep doing this until mapname is not like mapname?n

              Comment


              • #8
                Re: batch or vbs help

                here is what I've got so far. it is still a little broken with the odd case hostage hostage2a hostage2b
                and with opening the correct output file to append a line.

                any help?

                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

                Comment


                • #9
                  Re: batch or vbs help

                  edman747:

                  Hang in there.

                  I'm trying to motivate our best scripter to jump in. Being second / third / ... best, I'll try to see if I can get some time tonight after all have gone to bed.

                  Looks like you have a great start.
                  Cheers,

                  Rick

                  ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                  2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

                  Comment


                  • #10
                    Re: batch or vbs help

                    Here's what I'd do:

                    execute command to sort directory alpha-numerically ascending (a-z, etc), then read the directory for a file name, chop off the extension, and then add it to the cfg, with nextmap preceding it. Can't hurt having nextmap before all of the map names if some of the map names need it, right?

                    HL rocks, bring back as_docks!
                    ** Remember to give credit where credit is due and leave reputation points where appropriate **

                    Comment


                    • #11
                      Re: batch or vbs help

                      hello,
                      here is a partial solution. I created a fake crisis1 and a toonrun4. also I skiped all the half-life single player maps with basenames like c1 c2 c3. they already work.

                      it produces a text file which could be the basis for a batch script.
                      echo nextmap afrikakorps2 >>afrikakorps1.cfg
                      echo nextmap afrikakorps3 >>afrikakorps2.cfg
                      echo nextmap crisis2 >>crisis1.cfg
                      echo nextmap hostage2a >>hostage.cfg
                      echo nextmap hostage2b >>hostage2a.cfg
                      echo nextmap svencoop2 >>svencoop1.cfg
                      echo nextmap toonrun2 >>toonrun1.cfg
                      echo nextmap toonrun3 >>toonrun2.cfg
                      echo nextmap toonrun4 >>toonrun3.cfg

                      but what I would really like to do is edit the correct map.cfg file.
                      in the "for each loop" at the end, the one that eliminates the painful nested if's
                      am not sure how to open/close the correct config file on the fly.

                      it should open afrikakorps1.cfg and
                      append "nextmap afrikakorps2" to the afrikakorps1.cfg
                      then open afrikakorps2.cfg and
                      append "nextmap afrikakorps3" to the afrikakorps2.cfg

                      any ideas?

                      --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

                      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)
                      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) & oMatch.Submatches(1)
                      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 i

                      For Each strBase in dicBaseNames.Keys
                      For i = 1 To UBound(dicBaseNames(strBase))
                      If strBase <> "c" then
                      strOutput = "echo nextmap" & " " & strbase & dicBaseNames(strBase)(i) & " " & ">>" & strBase & dicBaseNames(strBase)(i - 1) & ".cfg"
                      objLogFile.writeline strOutput
                      End If
                      Next
                      Next

                      ' 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 = "echo." & " " & ">>" & strname & ".cfg"
                      ' objLogFile.writeline strOutput
                      ' strOutput = "echo nextmap" & " " & strbase2 & strnumber2 & " " & ">>" & strname & ".cfg"
                      ' objLogFile.writeline strOutput
                      ' End If
                      ' If strNumber2 = "1" Or strNumber2 = "2a" Then
                      ' strName3 = arrTestNames(i + 2)
                      ' strBase3 = GetBaseName(strName3)
                      ' If StrComp(strBase3, strBase) = 0 Then
                      ' strNumber3 = GetSequenceNumber(strName3)
                      ' strOutput = "echo." & " " & ">>" & strname2 & ".cfg"
                      ' objLogFile.writeline strOutput
                      ' strOutput = "echo nextmap" & " " & strbase3 & strnumber3 & " " & ">>" & strname2 & ".cfg"
                      ' objLogFile.writeline strOutput
                      ' End If
                      ' End If
                      ' If strNumber3 = "2" Then
                      ' strName4 = arrTestNames(i + 3)
                      ' strBase4 = GetBaseName(strName4)
                      ' If StrComp(strBase4, strBase) = 0 Then
                      ' strNumber4 = GetSequenceNumber(strName4)
                      ' strOutput = "echo nextmap" & " " & strbase4 & strnumber4 & " " & ">>" & strname3 & ".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 = "echo." & " " & ">>" & strname & ".cfg"
                      ' objLogFile.writeline strOutput
                      ' strOutput = "echo 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 = "echo." & " " & ">>" & strname2 & ".cfg"
                      ' objLogFile.writeline strOutput
                      ' strOutput = "echo nextmap" & " " & strbase3 & strnumber3 & " " & ">>" & strname2 & ".cfg"
                      ' objLogFile.writeline strOutput
                      ' End If
                      ' If strNumber3 = "3" Then
                      ' strName4 = arrTestNames(i + 3)
                      ' strBase4 = GetBaseName(strName4)
                      ' If StrComp(strBase4, strBase) = 0 Then
                      ' strNumber4 = GetSequenceNumber(strName4)
                      ' strOutput = "echo nextmap" & " " & strbase4 & strnumber4 & " " & ">>" & strname3 & ".cfg"
                      ' objLogFile.writeline strOutput
                      ' End If
                      ' End If
                      ' End If
                      ' End If
                      ' Next

                      End Sub

                      Thanks.

                      Comment


                      • #12
                        Re: batch or vbs help

                        here is a solution. users can put this script in their Half-Life\svencoop\maps directory. and double click to run it.
                        a small dialog pops up, saying:
                        Series Map Search Completed
                        Please check updated map.cfg's
                        See search.log for details.

                        the user has to click ok to dismiss the dialog.
                        when they open search.log in notepad, they will see something similar to this:
                        changelevel bug squished. Summary of changes:
                        afrikakorps1.cfg
                        nextmap afrikakorps2
                        afrikakorps2.cfg
                        nextmap afrikakorps3
                        hostage.cfg
                        nextmap hostage2a
                        hostage2a.cfg
                        nextmap hostage2b
                        svencoop1.cfg
                        nextmap svencoop2
                        toonrun1.cfg
                        nextmap toonrun2
                        toonrun2.cfg
                        nextmap toonrun3

                        the script is a little sloppy. I don't check to see if a previous search.log exist. and where I read the directory once just to get a count of map names. then redim the array using the count and read the directory again to fill the array. also I don't check to see if the correct config file exist before writing to it. but it does create a log showing which config files were updated. a couple of days ago I had never written a vbscript before. check out the for each loop where I step through the dictionary using the basename and strNumber. that is part is cool and it eliminates a huge painful nested if.

                        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
                        
                        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)
                            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 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"
                        
                        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) & oMatch.Submatches(1)
                                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 i
                                    strOutput = "changelevel bug squished. Summary of changes:"
                                    objLogFile.writeline strOutput
                        For Each strBase in dicBaseNames.Keys
                            For i = 1 To UBound(dicBaseNames(strBase))
                            If strBase <> "c" then
                            strOutput = strBase & dicBaseNames(strBase)(i - 1) & ".cfg"
                            objLogFile.writeline strOutput
                            strOutput = "  nextmap" & " " & strbase & dicBaseNames(strBase)(i)
                            objLogFile.writeline strOutput
                            objFSO.OpenTextFile(strBase & dicBaseNames(strBase)(i - 1) & ".cfg", 8).WriteLine _
                            "nextmap" & " " & strbase & dicBaseNames(strBase)(i)
                            End If
                            Next
                        Next
                            
                        End Sub
                        Thank You,

                        Comment


                        • #13
                          Re: batch or vbs help

                          It is really refreshing to see a first time poster describe the problem well, take a few pearls of wisdom from others, work out the solution, and post it back for all to see.

                          This is quite rare in my short time here.

                          edman747:

                          Please do consider lurking on these forums as often as you can and helping others with their problems as time allows. I can tell you have "The Right Stuff"
                          Cheers,

                          Rick

                          ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                          2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

                          Comment

                          Working...
                          X