Actually, I was setting the variable in both places. I tried it like this and it ignored my variable altogether. i don't get a messagebox no matter what happens, and the script continues on its merry way and deletes all my files. I WANT it to Quit so it doesn't process the last line where it deletes all the files on the thumbdrive. I think Richard H. hit on what needs doing. I need to delete each file as the copy is succesful. That way I don't delete files that didn't copy succesfully, and I don't end up with duplicates when one file fails and none of them are deleted.
Code:
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'
$Error = @error
If $Error <> 0
$MSG = Messagebox ("This" + $error + "went wrong","Error")
LogAction ("File " + $File + " was renamed to: " + $Date + '-' + $Time + '.WMA')
Quit
EndIF
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
I moved the $error = @error down below the loop because I couldn't get it to work inside the loop. The problem was that now I was only getting the result of the LAST file copied, and that meant I could loose data if the first file failed and the last succeded. As soon as I changed it from
$error = @error
If $Error <> 0
to
If @error <> 0
It works...
Of course, I'm pretty new, so it could be I just had something screwed up... Thanks for your help. I think I can take it from here.