Groups | Blog | Home
all groups > sql server dts > august 2005 >

sql server dts : Delete blank files via DTS


mitch
8/31/2005 11:27:23 AM
Hi,

The following code works perfectly but now I want to do a little tweak at a
different part of the DTS package. What I want to do is to delete files that
are blank so they are not FTP'd to the remote server (a zero byte TXT file).
I can see in my head what I need to do to the code, but I cannot figure it
out. It seems like I would have to add some type of IF statement?

This is the code that runs after the FTP part so the files do not get sent
again:

'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************

Function Main()

Dim objFSO
Dim objFolder
Dim objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Websites\LocalUser\web-forms\aio\")

For Each objFile In objFolder.Files
objFile.Delete True
Next

Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing

Main = DTSTaskExecResult_Success
End Function



Any help would be greatly appreciated.

Thanks!

Mitch

mitch
8/31/2005 3:59:39 PM
Allan,

Yes...I want it to delete files that are 0 bytes so they do not get FTP'd to
the remote server.

Could you please show me an example of how the File object could be used?

Thanks,

Mitch



[quoted text, click to view]

Allan Mitchell
8/31/2005 10:33:31 PM
Are you asking how to check a file's size?

The File object has a size property so as you loop over the files you check the size and
delete as appropriate

Allan



[quoted text, click to view]


Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.SQLIS.com - You thought DTS was good. here we show you the new stuff.
Allan Mitchell
8/31/2005 11:13:55 PM
You very nearly had it. Something like this should work

For Each f in Fold.Files
If f.Size = 0 THEN
f.Delete
End if
Next

Allan
[quoted text, click to view]


Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.SQLIS.com - You thought DTS was good. here we show you the new stuff.
mitch
9/1/2005 7:12:58 AM
Allan,

Thank you, it worked perfectly!!

I figure I would post the code so others may use it:

'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************

Function Main()

Dim objFSO
Dim objFolder
Dim objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\temp\test\")

For Each objFile in objFolder.Files
If objFile.Size = 0 THEN
objFile.Delete True
End if
Next

Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing

Main = DTSTaskExecResult_Success
End Function


MItch



[quoted text, click to view]

AddThis Social Bookmark Button