The thing is, he wants different error codes when the error occurs on the source file versus the error occurring on the destination file.
I also don't understand why the desitination file is opened with a repeat loop on error 70 (in use) when the contents are replaced in its entirety anyway. Whomever is using the file, well, whatever contents were there are gone now.
I don't use TRY..CATCH, but it sure looks like the long way here.
Announcement
Collapse
No announcement yet.
File Copy Function
Collapse
X
-
SHFileOperation might work for you. It will return a result code for you ( >0 = trouble).
Leave a comment:
-
-
This could be your problem...
To leave the TRY structure, execution must pass normally through END TRY, or by an EXIT TRY statement. Leaving a TRY block any other way is strongly discouraged because error trapping will remain disabled, and the previous ERR value will not be restored. Future versions of PowerBASIC may disallow such practices.
(PS. Very hard to follow without indents. I had to copy it into notepad and indent it to see what you had).
MCM
Leave a comment:
-
-
> I'm trying to put together a filecopy function with error checking.
Code:FILECOPY source$, dest$ IF ERR THEN ....
Leave a comment:
-
-
File Copy Function
I'm trying to put together a filecopy function with error checking.
Although I have error trapping turned on, I sometimes get an Error 75 from Powerbasic using the #DEBUG DISPLAY ON so the program waits for the user to click OK or Cancel. What I need is for the function to exit returning the error code.
Code:FUNCTION Perform_File_Copy( BYVAL SF AS STRING, BYVAL DF AS STRING ) AS LONG ' ' Do File Copy ' Return Error Code as -ve If Error Opening Source File ' Return Error Code as +ve If Error Opening Destination File ' on error goto Perform_File_Copy_Error_Handler ' LOCAL TS1 AS STRING LOCAL SF_Contents AS STRING LOCAL Han AS LONG LOCAL ErrCount AS LONG ' Han = FREEFILE ' TS1 = DIR$( SF ) ' IF SF = "" THEN ' FUNCTION = - 53 ' ELSE ' DO ' TRY ' <o><o><o><o> TRY ERROR TRAP <o><o><o><o> ' ERRCLEAR OPEN SF FOR BINARY LOCK READ WRITE AS #Han ' CATCH ' <o><o><o><o> CATCH ERROR TRAP <o><o><o><o> ' IF ErrCount = 80 OR ERR <> 70 THEN FUNCTION = - ERR EXIT FUNCTION END IF ' INCR ErrCount SLEEP 250 ' FINALLY ' <o><o><o><o> FINALLY ERROR TRAP <o><o><o><o> ' IF ERR = 0 THEN GET$ #Han, LOF( #Han ), SF_Contents CLOSE #Han EXIT DO END IF ' END TRY ' <o><o><o><o> TRY END ERROR TRAP <o><o><o><o> ' LOOP ' ErrCount = 0 ' DO ' TRY ' <o><o><o><o> TRY ERROR TRAP <o><o><o><o> ' ERRCLEAR OPEN DF FOR BINARY LOCK READ WRITE AS #Han ' CATCH ' <o><o><o><o> CATCH ERROR TRAP <o><o><o><o> ' IF ErrCount = 80 OR ERR <> 70 THEN FUNCTION = ERR EXIT FUNCTION END IF ' INCR ErrCount SLEEP 250 ' FINALLY ' <o><o><o><o> FINALLY ERROR TRAP <o><o><o><o> ' IF ERR = 0 THEN PUT$ #Han, SF_Contents SETEOF #Han CLOSE #Han EXIT FUNCTION END IF ' END TRY ' <o><o><o><o> TRY END ERROR TRAP <o><o><o><o> ' LOOP ' END IF ' exit function ' Perform_File_Copy_Error_Handler : function = err ' resume Perform_File_Copy_Error_Handler_Resume Perform_File_Copy_Error_Handler_Resume : END FUNCTION
Tags: None
-
Leave a comment: