bas7ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
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