Trying to write a vb script to delete all blank lines from a collection of .csv files in a folder (e.g. a.csv, b.csv, c.csv, all containing a single letter a,b,c, respectively, and some with blank lines). Here is my code, it runs without error but is not deleting the lines like it should. Suggestions?
sFolder = "C:\Users\akhoshkar\Documents\MyJabberFiles"
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each sFilename In objFSO.GetFolder(sFolder).Files
If UCase(objFSO.GetExtensionName(sFilename.Name)) = "CSV" Then
set objInFile = objFSO.OpenTextFile(sFilename, 1, true, 0)
Do Until objInFile.AtEndOfStream
strLine = objInFile.Readline
strLine = Trim(strLine)
If Len(strLine) > 0 Then
strNewContents = strNewContents & strLine & vbCrLf
set objOutFile = objFSO.OpenTextFile(sFilename, 2, true, 0)
I have attached a sample environment for those who want to verify the code. 3 .csv files and the script inside a folder. Extract to C:\ for it to work properly (or just change the working directory inside the script). Thanks in advance everyone!