Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript Does Not Run Properly

Status
Not open for further replies.

HarvMan

IS-IT--Management
Feb 11, 2004
13
Hi,

Trying to run a vbscript (below) using this command:
c:\windows\system32\cscript.exe bwqm.vbs

The purpose of the script is to read a text file and remove the first 4 characters in each line. However, the script is only processing the first record in the text file.

How to correct this? Thanks!

Code:

Const ForReading = 1
Const ForWriting = 2

Set objFSo = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\BWQMTest.txt", ForReading)

strContents = objFile.ReadAll
objFile.Close

intlength = Len(strContents)
strRemainder = Right(strContents, intLength - 4)
strNewContents = strRemainder

Set objFile = objFSO.OpenTextFile("C:\BWQMTest.txt", ForWriting)
objFile.WriteLine strNewContents

objFile.Close
 
This currently deletes blank lines, and expects both files to be present before hand.
Code:
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFileIn = objFSO.OpenTextFile("C:\svn\TextIn.txt", ForReading)
Set objFileOut = objFSO.OpenTextFile("C:\svn\TextOut.txt", ForWriting)
Do While(Not objFileIn.AtEndOfStream)
	strFileLine = objFileIn.ReadLine()
	If(len(strFileLine) > 5) Then
		objFileOut.WriteLine(Mid(strFileLine,5))
	else

		'don't know what you want here
		'objFileOut.WriteLine(strFileLine)
	End If
Loop 
objFileIn.Close
objFileOut.Close
Set objFSO = Nothing

Lodlaiden

If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
Thanks Qik3Coder ... that did the trick!
 
Hi Qik3Coder,

I am changing my approach. If a line contains \\ it indicates the start of a UNC path and I want to write out that line commencing with the position of \\

Not having any luck with this code. Suggestions? Thanks!

Const ForReading = 1
Const ForWriting = 2

Set objFSo = CreateObject("Scripting.FileSystemObject")
Set objFileIn = objFSO.OpenTextFile("C:\BWQMTest.txt", ForReading)
Set objFileOut = objFSO.OpenTextFile("C:\BWQMOut.txt", ForWriting)

Do While(Not objFileIn.AtEndOfStream)
strFileLine = objFileIn.ReadLine()
If InStr(strFileLine, "\\") > 0 Then
objFileOut.WriteLine(Mid(strFileLine,InStr(strFileLine, "\\")))
End If

Loop

objFileIn.Close
objFileOut.Close
 
I managed to resolve this problem. The input file was originally a .log file. I did not properly convert it to a .txt file.

Sorry!
 
As long as the .log file is plain text, there is no 'conversion' necessary, just use the file name in the '.OpenTextFile' method.

This:
Code:
Set objFileIn = objFSO.OpenTextFile("C:\svn\TextIn.[COLOR=red]txt[/color]", ForReading)
Becomes:
Code:
Set objFileIn = objFSO.OpenTextFile("C:\svn\TextIn.[COLOR=red]log[/color]", ForReading)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top