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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking status of a fso.movefile, fso.copyfile etc

Status
Not open for further replies.

uprichard

Programmer
May 2, 2002
16
I have a script that I use to perform filesystem functions. Is there anyway to check the status that comes back from the call?

I know I could do a check to see that a new file exists after a copy and that the file does not exist after a delete etc, but that seams very long approach.

Thanks for any help.


Set fso = CreateObject("Scripting.FileSystemObject")
Select Case Action_Value
Case "move"
fso.MoveFile Source_Value, Dest_Value
Case "rmdir"
fso.DeleteFolder Source_Value, TRUE
Case "mkdir"
fso.DeleteFolder Source_Value, TRUE
Case "delete"
fso.DeleteFile Source_Value, TRUE
Case "copy"
fso.CopyFile Source_Value, Dest_Value
Case Else
msgbox "Invalid arg"
End Select
 
You end up doing something like:
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Select Case Action_Value    
    Case "move"        
       fso.MoveFile Source_Value, Dest_Value
    :
    :
    Case Else
        msgbox "Invalid arg"
End Select
If Err.Number <> 0 Then
    MsgBox Action_Value & &quot; error #&quot; & CStr(Err.Number) & _
        &quot; (&quot; & Err.Description & &quot;)&quot;
    'Other stuff to handle error
    Err.Clear
End If
On Error GoTo 0
Of course you can get as fancy with your error handling as you choose. Better read up on VBScript error processing. I suggest:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top