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

552 views      
Thread locked
 

Messages in this Thread

 
94,800 Postings in 11,952 Threads, 348 registered users, 23 users online (1 registered, 22 guests)
Index | Admin contact |   Forum Time: Mar 29, 2020 - 7:56 am EDT  |  Hits:30,506,735  (3,029 Today )
RSS Feed