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.
Author |
Topic |
iloveorangesoda
Starting Member
30 Posts |
Posted - 2006-02-28 : 05:59:10
|
HiI 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?ThanksKarunakaran |
 |
|
iloveorangesoda
Starting Member
30 Posts |
Posted - 2006-02-28 : 07:51:55
|
Function Main()Call testfileMain = DTSTaskExecResult_SuccessEnd Functionsub 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=32end sub |
 |
|
karuna
Aged Yak Warrior
582 Posts |
Posted - 2006-02-28 : 09:47:32
|
Hope this helpsFunction Main()Call CopyFileMain = DTSTaskExecResult_SuccessEnd FunctionSub CopyFile()Const ForAppending = 8Const ForReading = 1Set objFSO = CreateObject("Scripting.FileSystemObject")Set File1 = objFSO.OpenTextFile("c:\a.txt", ForAppending)Set File2 = objFSO.OpenTextFile("c:\b.txt ", ForReading)strText = File2.ReadAllFile2.CloseFile1.WriteLine strTextFile1.CloseEnd Sub ThanksKarunakaran |
 |
|
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? |
 |
|
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. ThanksKarunakaran |
 |
|
|
|
|