Remove certain lines in a text file

March 23, 2011 at 14:48:04
Specs: Windows XP
I would like to remove lines from a text file if they have more than one space in the line. With the code below it will remove lines if they have one space. How do I fix it so that it will only remove lines that have more than one space?

Option Explicit

dim filepath, VBSName, objFSO, objTextFile, objTextFile2
dim fs, folder, file, item, line, fs1, filename

VBSname = wscript.scriptfullname

Filepath = left(VBSname, Len(VBSname) -(len(VBSname) - InstrRev(VBSname, "\")))

set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(FilePath)

For each item in folder.Files
If Right(, 3) = "txt" Then

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile (item, 1)
Set fs1 = objFSO.CreateTextFile ("temp.txt",True)
Set objTextFile2 = objFSO.OpenTextFile ("temp.txt", 8)

Do Until objTextFile.AtEndOfStream
Line = objTextFile.ReadLine
if 17 < Len(Line) then
If InStr(1,Line, " ",1) then
objTextFile2.writeline line
End If

set objTextFile = nothing
set objTextFile2 = nothing

filename =

objFSO.CopyFile "temp.txt", filename, true

objFSO.DeleteFile "temp.txt"

set objFSO = nothing
Set fs1 = nothing

End If

msgbox "Done!"

See More: Remove certain lines in a text file

Report •

March 25, 2011 at 22:31:46
is the split function supported?

arr = split(line, chr(32))
if ubound(arr) > 1 then ...

you might also try something like

dim i as integer, count as integer
count = 0

for i=1 to len(line) step 1
if mid(line, i, 1) = chr(32) then count = count + 1
next i

if count > 1 then ...

not sure which flavor of vb you're using, but maybe it will help.

Report •
Related Solutions

Ask Question