I have a text file with hundreds of blank lins scatered through out
the file. How Can I Delete the blank lines.
I found this script that will delete the first 5 lines of a file, so I
am guesing I could use it and Test for a blank line.
What would the Test be?
Set objFSO = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\Scripts'} Where " _
& "ResultClass = CIM_DataFile")
For Each objLogFile In colFiles
If objLogFile.Extension = "txt" Then
strFile = objLogFile.Name
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
i = 1
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If i > 5 Then
strContents = strContents & strLine & vbCrLf
End If
i = i + 1
Loop
objFile.Close
Set objFile = objFSO.OpenTextFile(strFile, ForWriting)
objFile.Write strContents
objFile.Close
End If
Next
the trick is easy. you actually do not need to delete the lines of the
document but create a new one without the empty lines.
You have everything you need in the code you posted. The only new thing
needed is a new file to write to.
Here is some pseudo code to help you.
open file A for reading
open file B for writing
Start loop until end of file A
read one line from A
if line is NOT empty
write line to B
end of loop
hope this helps, if you need more help don't hesitate to post again.
--
**********
Rafael T
"OldDog" <michael....@wellsfargo.com> wrote in message
news:ced0175c-5d3d-4b45...@t47g2000hsc.googlegroups.com...
Hi,
Thanks for the responce. Here is what I have so far, and it works to
an extent.
However, It turns out that not all the lines that I thought were
empty, are empty.
They start with a TAB charactor. Is there a way to detect if the new
line only has a TAB
charactor and skip that?
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='Y:\'} Where " _
& "ResultClass = CIM_DataFile")
For Each objLogFile In colFiles
If objLogFile.Extension = "txt" Then
strFile = objLogFile.Name
WScript.Echo strFile
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If strLine <> "" Then
strContents = strContents & strLine & VbCrLf
'WScript.Echo strContents
End If
the ASCII number for tab is 9, maybe you can use it to identify the line.
if strLine=chr(9) then
hope this helps,
--
**********
Rafael T
"OldDog" <michael....@wellsfargo.com> wrote in message
news:71c8b812-223b-4d5a...@b40g2000prf.googlegroups.com...