ZTree.com  | ZEN  | About...  

 Index   Back

[OT] Batch file to find and remove returns from a text file   [OT]

By: GoSlow2GoFast     RI  
Date: Jan 14,2016 at 07:56
In Response to: [OT] Batch file to find and remove returns from a text file (Neil Clough)

Could be done quite easily with a small VBS script, something like:

' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

' Get input file name from command line parm, if 2 parms entered
' use second as new output file, else rewrite to input file
If (WScript.Arguments.Count > 0) Then
strInFile = WScript.Arguments(0)
Else
WScript.Echo "No filename specified."
WScript.Quit
End If
If (WScript.Arguments.Count > 1) Then
strOutFile = WScript.Arguments(1)
Else
strOutFile = strInFile
End If

' Read file into an array
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strInFile, ForReading, False, TriStateUseDefault)
strData = objFile.ReadAll
objFile.Close

' Remove CR-LF pairs
strData = Replace(strData, vbCrLf, "")

' Rewrite file with any changes made
Set objFile = objFSO.OpenTextFile(strOutFile, ForWriting, True)
objFile.Write strData
objFile.Close

505 views      
Thread locked
 

Messages in this Thread

 
94,426 Postings in 11,918 Threads, 348 registered users, 7 users online (0 registered, 7 guests)
Index | Admin contact |   Forum Time: Sep 17, 2019 - 12:31 pm EDT  |  Hits:28,645,364  (1,364 Today )
RSS Feed