Jump to content


  • 0
wmmayms

Removing top rows from a unicode txt file

Question

When you run scheduled jobs in MS SQL you sometimes want to output the results to a txt file. This works like a charm...

 

However MS tends to add four annoying rows to the top of this output file. I thought it was easy to remove these rows with a simple vbs/batch command....but No!!

post-2500-12922302324313_thumb.jpg

 

 

Since it´s unicode format it gets a bit harder...

 

here is the code i ended up using:

 

'Written by wmmayms 13/12 - 2010

Option Explicit

strTextFile  = "<----ADD PATH TO YOUR TXT FILE HERE---->"

Dim objFSO, objFile , strTextFile, strData, strLine, arrLines, i
CONST ForReading = 1
CONST ForWriting = 2

'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'rename file
objFSO.MoveFile strTextFile, strTextFile & "_temp"

'Open the text file with unicode format (-1) - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile & "_temp",ForReading,false,-1).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

'Create new file in unicode format
Set objFile = objFSO.CreateTextFile(strTextFile, false, true)


'Loop through all values and remove rows 1-4
i=0
For Each strData In arrLines 
if i=0 or i=1 or i=2 or i=3 Then
'Do Nothing
else
objFile.WriteLine(strData)
end if
i=i+1
next

'Remove temp txt
objFSO.DeleteFile strTextFile & "_temp", True 

'Cleanup
Set objFSO = Nothing
Set objFile = Nothing 

 

 

 

 

It´s not pretty but it work =)

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.