Search code examples
directoryexistsqbasicgw-basic

How to test if a directory exist in qbasic?


I'm writing a program in Qbasic. I'd like to know how to test if a folder exists.

The idea is:

IF "c:\user\basic\blablabla\" exists (?? how to programm the "exist" test?)
THEN CHDIR "c:\user\basic\blablabla\"
ELSE 
MKDIR "c:\user\basic\blablabla\"
CHDIR "c:\user\basic\blablabla\"
ENDIF

I hope i'm clear enough,

thank you very much for your suggestions !

:)


Solution

  • Try changing the directory to blablabla. If it doesn't exist, there'll be an error. Trap this error and specify an error handling routine.

    ON ERROR GOTO doesnotexist
    CHDIR "c:\user\basic\blablabla\"
    END
    
    doesnotexist:
    MKDIR "c:\user\basic\blablabla\"
    CHDIR "c:\user\basic\blablabla\"
    RESUME NEXT