bas7ex.hlp (Topic list)
CHDIR and MKDIR Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example uses the MKDIR statement to create a subdirectory. The
'AddADir procedure uses the CHDIR statement with the ON ERROR statement
'to chek if the subdirectory already exists. If it does not exist, the
'error-handling routine traps error 76, prompts the user, and creates
'the directory.
 
DECLARE SUB AddADir (DestDir$)
 
CLS
AddADir "TESTDIR"
 
SUB AddADir (DestDir$)
ON LOCAL ERROR GOTO ErrHandler  'Set up the local error handler.
    CurDirName$ = CURDIR$       'Preserve the name of the current directory.
    CHDIR DestDir$              'Change to DestDir$ - Error 76 if not exist.
    CHDIR CurDirName$           'Change back to original directory.
    EXIT SUB
 
ErrHandler:
    IF ERR = 76 THEN
        PRINT "Directory does not exist. Create ?";
        Ans$ = INPUT$(1)
        PRINT Ans$
        IF UCASE$(Ans$) = "Y" THEN
            MKDIR DestDir$      'Make the directory.
            PRINT DestDir$; " directory created."
            RESUME NEXT
        ELSE
            PRINT DestDir$; " directory NOT created."
        END IF                  'Return control to caller.
    END IF
    RESUME NEXT                 'Just continue.
END SUB