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

514 views      
Thread locked
 

Messages in this Thread

 
94,579 Postings in 11,930 Threads, 348 registered users, 13 users online (0 registered, 13 guests)
Index | Admin contact |   Forum Time: Nov 14, 2019 - 3:44 am EST  |  Hits:29,092,397  (2,313 Today )
RSS Feed