I was hoping someone can help me with this script. I am using several other peoples UDFs to make a script that will copy files from USB thumb drives, rename them to the current data and time, and then delete the originals from the device. Everything is working perfectly, but the problem is that I am using a "For Each" statement and I can't figure out how to verify that the files are being copied BEFORE deleting the originals. Because it is a loop, I am only receiving the error code returned for the LAST file copied. If there are 4 files and the first three fail, but the last one succeeds, then the script will happily continue and delete the originals. I need some way to make the script stop if an error is detected. I had a file get lost yesterday because the workstation lost network connectivity during the transfer. The script just kept going and purged all the files on the thumbdrive. Any suggestions would be greatly appreciated. Here is the pertinent part of the script. The whole thing is very long and wont fit here. I am using the DirPlus UDF written by Bryce (I think).
Code:
  
;=======================================================================
; Copy files
;=======================================================================

;Call the Dirplus UDF.
Call @SCRIPTDIR + "\DirPlus.udf"
;
;Enumerate all FILES on drive x:
$Files = DirPlus(@SCRIPTDIR,'/S /F WMA')
;
;Split the date on the / character and the join the parts with no separation characters.
$Date = Join(Split(@Date,'/'),"")
;
;Get the filename without the drive letter so start counting at the 4th character.
$Filename = SubStr ($File, 4)
;
;Get the extension of the file.
$Ext = SubStr ($Filename, Len($Filename) - 4)
;
;Do the stuff inside the For each--next loop for each file found.
For Each $File in $Files
If $File
;Split the time at the : character and then join the parts with no separation characters.
$Time = Join(Split(@TIME,':'),"")
;Copy the file and rename it during the copy process.
Copy $File 'X:\$StringUsername\' + $Date + '-' + $Time + '.WMA'
LogAction ("File " + $File + " was renamed to: " + $Date + '-' + $Time + '.WMA')
;Sleep 1 second to get the $Time var different for each file.
Sleep 1
EndIf
Next

$Error = @ERROR

If $Error = "-1"
$Msg = MessageBox ("There were no files found on the recorder","ERROR")
Quit
EndIf

If $Error = "3"
$Msg = MessageBox = ("The path was not found. There may have been a network connectivity problem." +
" Please try again. If you continue to have trouble, please call the Helpdesk.","Error")
Quit
EndIf

If $Error > 3
$Msg = MessageBox = ("Error number: " + $Error + " An unknown error has occurred. Please try again." +
" If you continue to have trouble, please call the Helpdesk.","Error")
Quit
EndIf

If $Error <> "0"
$Msg = MessageBox ("Error number: " + $Error + " An unknown error has occurred. Please try again." +
" If you continue to have trouble, please call the Helpdesk.","Error")
Quit
EndIf

If $Error = "0"
$Msg = MessageBox ('Your files have been successfully copied to" +
" the X:\'+ $StringUsername + ' folder.','File Copy Result')
EndIf


;=======================================================================
; Clean Up
;=======================================================================
Copy "\\ServerName\netlogon\Update.exe" @SCRIPTDIR /h /r
Copy "\\ServerName\netlogon\Upload Audio Files.exe" @SCRIPTDIR /r
Use W: /Del
Del @SCRIPTDIR+'\DSS_FLDA\*.*' /c
Del @SCRIPTDIR+'\DSS_FLDB\*.*' /c
Del @SCRIPTDIR+'\DSS_FLDC\*.*' /c
Del @SCRIPTDIR+'\DSS_FLDD\*.*' /c
Del @SCRIPTDIR+'\DSS_FLDE\*.*' /c
Del @SCRIPTDIR+'\DSS_FLDF\*.*' /c