Solved

VBScript to edit multiple text files

Posted on 2008-10-21
4
979 Views
Last Modified: 2011-04-14
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
Comment
Question by:drezner7
  • 2
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
Comment Utility
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
 

Author Comment

by:drezner7
Comment Utility
Very Nice, it works great.
0
 

Author Closing Comment

by:drezner7
Comment Utility
Very Nice!!
0
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
Cool!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now