Solved

VBScript to edit multiple text files

Posted on 2008-10-21
4
993 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
ID: 22767391
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
ID: 22767524
Very Nice, it works great.
0
 

Author Closing Comment

by:drezner7
ID: 31508272
Very Nice!!
0
 
LVL 76

Expert Comment

by:David Lee
ID: 22767581
Cool!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

19 Experts available now in Live!

Get 1:1 Help Now