CHDIR Statement ---------------------------------------------------------------------------- Action Changes the current default directory for the specified drive. Syntax CHDIR pathname$ Remarks The argument pathname$ is a string expression identifying the directory that is to become the default directory. The pathname$ expression must have fewer than 64 characters. It has the following syntax. -drive.--\-directory-\ directory-... The argument drive is an optional drive specification. If you omit drive, CHDIR changes the default directory on the current drive. CHDIR cannot be shortened to CD. The CHDIR statement changes the default directory but not the default drive. For example, if the default drive is C, the following statement changes the default directory on drive D, but C remains the default drive. CHDIR "D.\TMP" Use CURDIR$ to return the current directory and CHDRIVE to change the default drive. See Also MKDIR, RMDIR Example This example uses the MKDIR statement to create a subdirectory. The AddADir procedure uses the CHDIR statement with the ON ERROR statement to check 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 (DstDir$) 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