Re: Remove Blank Line and/or Additional CRLF From End of File

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 10/14/04


Date: Thu, 14 Oct 2004 17:03:13 +0200

O. Johnson wrote:

> Wrote a VBscript to extract the first 5698 characters of a 30,000+ character
> per line Lawson extract file, so it can be imported into our check writing
> software. The issue is I get a blank line and/or additional CRLF at the end
> of the file which the check writing software views as a blank record and
> errors on the import. What can I add to my script(entire script below) to
> remove this additional blank line and/or CRLF so it doesn't have to manually
> be removed as they are doing today?
Hi

This should do it:

'--------------------8<----------------------
Option Explicit

Const OpenAsASCII = 0
Const OverwriteIfExist = -1
Const FailIfNotExist = 0
Const ForReading = 1

Dim fso, strFiles, strSourceFile, strOutputFile, strOutputLine
Dim tsout, tsin, strLine

strSourceFile = "C:\pmtout\pmtout.txt"
strOutputFile = "C:\pmtout\pmtout.pmt"

set fso = CreateObject("Scripting.FileSystemObject")

' 'Create new file (will delete any old file)
set tsout = fso.createTextFile(strOutputFile, OverwriteIfExist, OpenAsASCII)

' open input file
set tsin = fso.openTextFile(strSourceFile, ForReading, _
                                      FailIfNotExist, OpenAsASCII)

Do Until tsin.atEndOfStream
   strLine = tsin.ReadLine 'Read line into memory

   'Reset to first 5698 COLUMNS from left and write to output file
   tsout.Write Left(strLine,5698)

   ' To avoid blank line at end
   If not tsin.atEndOfStream Then
     tsout.WriteLine
   End If
Loop

tsout.close
tsin.close

msgbox "DONE!"

'--------------------8<----------------------

-- 
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx


Relevant Pages

  • Re: Remove Blank Line and/or Additional CRLF From End of File
    ... >> of the file which the check writing software views as a blank record and ... > Dim fso, strFiles, strSourceFile, strOutputFile, strOutputLine ... > Dim tsout, tsin, strLine ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.vbscript)
  • Re: Regular Expressions
    ... Const OpenAsASCII = 0 ... Set oFSO = CreateObject ... bCheckForG1AtNextLoop = False ' init value ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.inetsdk.programming.scripting.vbscript)
  • Re: Get & Set Services status per script ?
    ... Const OpenAsASCII = 0 ... sComputer = oWshNet.ComputerName ... On Error Goto 0 ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.vbscript)
  • Re: Disconnect user after closed IE
    ... ' will ' actually end up as a forced shutdown (a bug in the WMI ... use "Logoff" instead of "Logoff_Force". ... Const EWX_SHUTDOWN = 1 ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.scripting.wsh)
  • Re: Randomising a text file
    ... > it and overwrite the original? ... Const OpenAsASCII = 0 ... Dim arOut ... -- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: ...
    (microsoft.public.scripting.vbscript)