Home > Archive > MS SQL Server DTS > September 2005 > Error handling of file in use









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Error handling of file in use
Stijn Verrept

2005-09-30, 7:23 am

I read import a text file and need to delete it afterwards. I don't
know any VBScript so I had to look up some code to delete it. I found
the following:

'*******************
********************
********************
***********
' Visual Basic ActiveX Script
'*******************
********************
********************
************
*
Option Explicit

Function Main()
Dim oFSO
Dim sSourceFile

Set oFSO = CreateObject("Scripting.FileSystemObject")

sSourceFile = "C:\Output.txt"

' Check if file exists to prevent error
If oFSO. FileExists(sSourceFi
le) Then
oFSO.DeleteFile sSourceFile
End If

' Clean Up
Set oFSO = Nothing

Main = DTSTaskExecResult_Su
ccess
End Function


However, it could be that the file is locked and the delete fails. In
that case I need the DTS package to sleep for a couple of seconds and
then try again. How do I do this?


Thanks in advance,

Stijn Verrept.
irfankhanpatha via SQLMonster.com

2005-09-30, 7:23 am

Do error trapping the same by using err.number . If the file is in use than
skip the deleting process. You can delete the same file the next time when u
run function (That means at the starting of the function before using the
file.).

Stijn Verrept wrote:
>I read import a text file and need to delete it afterwards. I don't
>know any VBScript so I had to look up some code to delete it. I found
>the following:
>
> '*******************
********************
********************
***********
>' Visual Basic ActiveX Script
> '*******************
********************
********************
************
>*
>Option Explicit
>
>Function Main()
> Dim oFSO
> Dim sSourceFile
>
> Set oFSO = CreateObject("Scripting.FileSystemObject")
>
> sSourceFile = "C:\Output.txt"
>
> ' Check if file exists to prevent error
> If oFSO. FileExists(sSourceFi
le) Then
> oFSO.DeleteFile sSourceFile
> End If
>
> ' Clean Up
> Set oFSO = Nothing
>
> Main = DTSTaskExecResult_Su
ccess
>End Function
>
>However, it could be that the file is locked and the delete fails. In
>that case I need the DTS package to sleep for a couple of seconds and
>then try again. How do I do this?
>
>Thanks in advance,
>
>Stijn Verrept.

Stijn Verrept

2005-09-30, 7:23 am

irfankhanpatha via webservertalk.com wrote:

> Do error trapping the same by using err.number . If the file is in
> use than skip the deleting process. You can delete the same file the
> next time when u run function (That means at the starting of the
> function before using the file.).


Thanks for your reply. I cannot delete the same file the next time
because then I will have doubles in the database. Another application
is filling it sometimes so I need to make sure it is deleted.
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com