Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting text file contents 1

Status
Not open for further replies.

AngelB

Programmer
Feb 9, 2004
1,477
GB
Hi All

Does anyone know how (if possible) to delete the contents of a text file using DTS? Can I use similar syntax to TRUNCATE TABLE? Would I have to use an ActiveX script?

Thanks in advance

Geraint

 
ActiveX seems simple enough. Good luck!

Code:
FUNCTION Main()
	DIM oFSO
	DIM oTextFile

	'------ Set up text file
	IF oFSO.FileExists("FILENAME.EXT") THEN
		oFSO.DeleteFile("FILENAME.EXT")
	END IF

	SET oTextFile = oFSO.CreateTextFile("FILENAME.EXT")
	oTextFile.Close

	SET oFSO = nothing
	SET oTextFile = nothing

	Main = DTSTaskExecResult_Success
END FUNCTION

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Thanks for the quick reply John. I've put my filename into the code you provided (all looks good)

FUNCTION Main()
DIM oFSO
DIM oTextFile

'------ Set up text file
IF oFSO.FileExists("C:\DeleteTest.txt") THEN
oFSO.DeleteFile("C:\DeleteTest.txt")
END IF

SET oTextFile = oFSO.CreateTextFile("C:\DeleteTest.txt")
oTextFile.Close

SET oFSO = nothing
SET oTextFile = nothing

Main = DTSTaskExecResult_Success
END FUNCTION

However, this runs into a problem at line 9 where I get an error: Object Required 'oFSO'. The object has been declared and I haven't got any spelling mistakes. The code even passes the parser in the Script window. Any ideas why it won't work?

Thanks
Geraint
 
Sorry John, please ignore last post. Should have instantiated oFSO object thus:

set oFSO = CreateObject("Scripting.FileSystemObject")

It now works

Thanks

Geraint
 
My bad. Cut and paste error. [tongue] Glad to help.

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top