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!!
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
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.
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!!
Since it´s unicode format it gets a bit harder...
here is the code i ended up using:
It´s not pretty but it work =)
Share this post
Link to post
Share on other sites