Page 1 of 1

How do you delete lines in a txt file using vbscript

Posted: Mon Jul 07, 2008 2:46 pm
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.

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

Posted: Mon Jul 07, 2008 3:20 pm
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