| 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.
|
|
|
|