Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Export data to text file without overwriting file

Author  Topic 

iloveorangesoda
Starting Member

30 Posts

Posted - 2006-02-28 : 05:59:10
Hi

I have set up a dts package that will take data from a sql database table and write it to a text file. I used the ActiveX script task to write vb script using the FileSystemObject to write to the text file. This works fine the first time it is run, the problem I am having is the next time I try to run the dts package it overwrites what was previously in the file. If possible I would like to append to the top of the file. I am not sure how to do this. If it can be done using vbscript can someone give me a sample as I am not great with vbscript.

Thanks

karuna
Aged Yak Warrior

582 Posts

Posted - 2006-02-28 : 07:25:51
can you post your existing vbscript code?

Thanks

Karunakaran
Go to Top of Page

iloveorangesoda
Starting Member

30 Posts

Posted - 2006-02-28 : 07:51:55
Function Main()
Call testfile
Main = DTSTaskExecResult_Success
End Function

sub testfile()
set fsys=CreateObject( "Scripting.FileSystemObject")


'msgbox(fsys.FileExists("C:\TextDts.txt"))


set file=fsys.GetFile("C:\TextDts.txt ")


msgbox(file.name & vbcrlf & file.DateCreated & vbcrlf & file.Size)

fsys.CopyFile file, "C:\Destin.txt"


set file2=fsys.Getfile("C:\Destin.txt")


file2.Attributes=32



end sub
Go to Top of Page

karuna
Aged Yak Warrior

582 Posts

Posted - 2006-02-28 : 09:47:32
Hope this helps

Function Main()

Call CopyFile

Main = DTSTaskExecResult_Success
End Function

Sub CopyFile()
Const ForAppending = 8
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set File1 = objFSO.OpenTextFile("c:\a.txt", ForAppending)
Set File2 = objFSO.OpenTextFile("c:\b.txt ", ForReading)

strText = File2.ReadAll
File2.Close
File1.WriteLine strText
File1.Close

End Sub


Thanks

Karunakaran
Go to Top of Page

iloveorangesoda
Starting Member

30 Posts

Posted - 2006-02-28 : 10:21:11
Brilliant Thanks a lot

One last question - How would I go about clearing a text file of all of its data?
Go to Top of Page

karuna
Aged Yak Warrior

582 Posts

Posted - 2006-02-28 : 10:37:01
quote:
Originally posted by iloveorangesoda


One last question - How would I go about clearing a text file of all of its data?



You mean you want to delete the entire contents of that specific file?
In that case, I would simply delete the file and create another file.

Thanks


Karunakaran
Go to Top of Page
   

- Advertisement -