• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1030
  • Last Modified:

VBScript to edit multiple text files

I would like to be able to edit multiple files with one run of this script:

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile ("C:\054.log")
Dim objOut : Set objOut = objFSO.CreateTextFile ("C:\StrippedLogFiles\054.txt")

Do While Not objFile.AtEndOfStream
  strData = Trim(objFile.ReadLine)
  If Left(strData, 1) <> "#" Then
    iValue = Mid(strData, InstrRev(strData, " "))
    If iValue > 5000 Then objOut.WriteLine strData
  End If
Loop
 

objOut.Close
objFile.Close

for instance 054.log is shown in this script, it writes to 054.txt.  i would like to use 054-064.log and have them write to 054-064.txt respectivly.
0
drezner7
Asked:
drezner7
  • 2
  • 2
1 Solution
 
David LeeCommented:
Hi, drezner7.

Create an array of file names then use a FOR ... NEXT loop to process them.  Something like this
Dim objFSO, objFile, objOut, arrFiles, varFilename
arrFiles = Array("054.log","055.log","056.log")
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each varFilename in arrFiles
    Set objFile = objFSO.OpenTextFile ("C\" & varFilename)
    Set objOut = objFSO.CreateTextFile ("C:\StrippedLogFiles\" & Replace(varFilename,"log","txt"))
    Do While Not objFile.AtEndOfStream
        strData = Trim(objFile.ReadLine)
        If Left(strData, 1) <> "#" Then
            iValue = Mid(strData, InstrRev(strData, " "))
            If iValue > 5000 Then objOut.WriteLine strData
        End If
    Loop
    objOut.Close
    objFile.Close
Next

Open in new window

0
 
drezner7Author Commented:
Very Nice, it works great.
0
 
drezner7Author Commented:
Very Nice!!
0
 
David LeeCommented:
Cool!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now