General discussion
August 16, 2007 at 08:57 AM
developer

wscript to list files in a folder

by developer . Updated 19 years, 2 months ago

Can anyone see what is wrong with this script? I am new to wsh, but am a procedural programmer, so this should NOT be that hard. Which brings me to the subject of debug. I try to use Windows Debugger, but can’t seem to get it to watch my variables and step through my code.

All I want this script to do is read the files from a specific folder, one at a time, parse out three lines of the text file, beginning with the line that has a specific string, and output to a text file (which I accomplish with >> POPParse.txt in the command line.)

It doesn’t seem to want to loop through the files. It gets the first one and quits.

‘Run this script with wscript //nologo ReadPOPFile.vbs >> c:\POPParse.txt
Dim folder
Dim sOutput
Dim FolContent

Const ForReading = 1
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set folder = objFSO.GetFolder(“c:\MerakBounces\”)
Set FolContent = folder.Files

For each file In FolContent
Set objTextFile = objFSO.OpenTextFile(file)

Do While objTextFile.AtEndOfStream <> True
If inStr(objTextFile.Readline, ” —– Transcript of session follows —–“) Then

strLineOneParse = objTextFile.Readline
strLineTwoParse = objTextFile.Readline
strLineThreeParse = objTextFile.Readline
Wscript.Echo strLineOneParse & ” , ” & strLineTwoParse & ” , ” & strLineThreeParse & VbCrLf
‘objTextFile
set objTextFile.AtEndOfStream = True
On Error Resume Next
Else
objTextFile.Skipline
On Error Resume Next

End If
strLineOneParse = ” ”
strLineTwoParse = ” ”
strLineThreeParse = ” ”
i = i + 1

Loop
objTextFile.Close()
Next

This discussion is locked

All Comments