How do you delete lines in a txt file using vbscript

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
Post Reply
James D
Senior Member
Posts: 134
Joined: Wed Jun 06, 2007 3:30 pm
Location: Baja California

How do you delete lines in a txt file using vbscript

Post by James D »

Hello Everyone,

I have a small problem. What is the best way to delete or remove "Blank lines" in a *.txt file using a vbscript?

Ex.
Music1
Music2

Music4

Music6


I want the *.txt file to read

Music1
Music2
Music4
Music6

I do not mind making a script device that will remove all the blanks. But I am running into some problems.

Thanks alot.
James D
Senior Member
Posts: 134
Joined: Wed Jun 06, 2007 3:30 pm
Location: Baja California

Re: How do you delete lines in a txt file using vbscript

Post by James D »

Nevermind I found a script on the web...

Below is the attached script.

SAVElistNM = GetPropertyValue("HBdevice.HBProperty")
TotalPLNM = ("YourDir" & SAVElistNM)
'msgbox TotalPLNM 'stands for Total Play List Name ex. C:\HB_PLAYLIST\TESTLocalTest.m3u

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(TotalPLNM, ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.Readline
strLine = Trim(strLine)
If Len(strLine) > 0 Then
strNewContents = strNewContents & strLine & vbCrLf
End If
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile(TotalPLNM, ForWriting)
objFile.Write strNewContents
objFile.Close
Post Reply