Anyway when 'edit' is selected the file is passed to the editor (Jarte) then passed to another PB prog that makes a few modifications which are mainly cosmetic to correct grammar etc..
Now the problem bit -
The modify program checks to see if a backup exists and if it does it calls 'RecycleFile()' to send it to the recycle bin, then copies the existing file with '.back' appended to my backup folder, deletes the existing file and saves the new modified file.
If I run the modify program on it's own there is no problem, but when it is called from the viewer with 'runprogram()' I get an error message saying that it cannot delete the file as it can't open it. Since it is called with 'runprogram()' I have to compile the programs to test them and debugging consists of placing messagerequesters at strategic points to see where the problem is. In this way I have tracked it to my 'RecycleFile()' bit.
Code: Select all
Procedure.l Exist(File$) ;- Check a drive + file exists, without system requesters etc.
; Check if a drive + file exists
; Returns 1 if exists, else 0
Protected EFlag.l, OldErrorMode.l, Junk.l
OldErrorMode = SetErrorMode_(1) ; Turn off screen error messages
If GetFileAttributes_(@File$)=-1 ; Get file butes. -1 = fail
Junk.l=GetLastError_() ; Get last error, to flush system
SetLastError_(0) ; Set error to zero
EFlag.l = 0 ; Return value to flag FAIL
Else
EFlag.l = 1 ; Return value to flag a PASS
EndIf
SetErrorMode_(OldErrorMode) ; Reset the error flags
ProcedureReturn EFlag
EndProcedure
;
Procedure RecycleFile(file$)
SHFileOp.SHFILEOPSTRUCT
SHFileOp\pFrom=@file$
SHFileOp\wFunc=#FO_DELETE
SHFileOp\fFlags=#FOF_ALLOWUNDO | #FOF_NOCONFIRMATION ; without #FOF_NOCONFIRMATION you get a messagerequester asking to confirm sending to recycle bin
SHFileOperation_(SHFileOp)
EndProcedure
;
NewName$=backuploc$+nameonly$+".bak"
; from here the files start getting overwritten, deleted and changed
If Exist(NewName$) ; COMMENT NEXT LINE OUT AND NO PROBLEM
null=RecycleFile(NewName$) ; last backup version is deleted by sending to recycle bin
EndIf
The other funny bit is that although I get the message saying it can't open the file, it actually works! The new file is where it should be, the old file becomes a '.bak' file and the old '.bak' goes to the recycle bin.
Any ideas as to why I get the error message when there appears to be no error would be appreciated.