On Mon, Jul 14, 2003 at 10:07:00AM -0700, Stannard, Rick wrote:
> 
>    Hello,
>      I have been using and modifying a macro that all of you have been
>    adding to without your knowledgefor quite a while, improving on it as
>    I go.  I just came up with something that I know there is a possibly
>    simple answer for.
> 
>      How can I have my macro check to see if the file already exists and
>    ask me if I really want to overwrite it or not?
>      Then if I don't want it to overwrite, is it possible to ask me to
>    specify a file name to save it under and of course check to see if
>    this file name is unused.

Following is a snippet using the F_EXIST() and F_ERROR() functions,
hopefully it'll get you started:

@FILE_NAME
//Get / validate file name
prompt[TX="Name for Code file:",VN="FILE",LR=10,LC=15] 

IF(F_EXIST(#FILE)=0)
  AUTO_ANSWER[AA=YES]       //if file doesn't exist automatically overwrite
ELSE
  AUTO_ANSWER[AA=OFF]       //otherwise prompt for overwrite permission
ENDIF

F_OPEN[FN=#FILE, TY=W]      //try to open file for writing

IF(F_ERROR() > 0)           //if open fails, or file is not writeable: 
  #ERROR_STRING=F_ERRSTR()  //save the error type
  F_CLOSE[FN=#FILE]         //close the file
  GOTO(EXIT_FAILURE)        //exit with an error
ELSE
  F_CLOSE[FN=#FILE]         //otherwise simply close the file
ENDIF

//Houston, we have a problem.
@EXIT_FAILURE
pause[TX=STRTMP("Error!!\n
%#ERROR_STRING"),LR=10,LC=15,PT=0] 
GOTO(DONE)

//Done
@DONE

-- 
Kelly D. Grills
[EMAIL PROTECTED]

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to