Search code examples
basicqbasicqb64

How To Get Default Directories Of Drives In QB64


I have been using the following code to get the default directories of all drives, however I don't want to use _CWD$

is there a more efficient way to do this?

REM get default directory of drives.
ON ERROR GOTO ErrSub
FOR D = 1 TO 26
    D$ = CHR$(D + 64) + ":"
    DataError = 0
    CHDIR D$
    IF DataError = 0 THEN
        PRINT _CWD$
    END IF
NEXT
END

ErrSub:
DataError = ERR
RESUME NEXT

Solution

  • Have also noticed the default directory is not always the directory where a file was started from, so, here is a sample describing each:

    ' directory file was loaded from
    PRINT _CWD$
    
    ' declare external libraries.
    DECLARE DYNAMIC LIBRARY "kernel32"
        FUNCTION SetCurrentDirectoryA% (f$)
    END DECLARE
    
    ' force default path
    x$ = _STARTDIR$
    f$ = x$ + CHR$(0)
    x = SetCurrentDirectoryA(f$)
    
    ' directory where user is in dos
    PRINT _CWD$