QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The _STARTDIR$ function returns the user’s working directory when the program was started.

Syntax

callPath$ = _STARTDIR$

Description

The user’s working directory depends on how the program was launched. Note that these are ultimately controlled by the launching environment, so might differ in non-standard setups.

The value of _STARTDIR$ may differ from _CWD$ even at program start, because QB64 program change their current directory to the binary’s location. _STARTDIR$ is the directory inherited from the user’s environment, while _CWD$ will start off as the location of the program binary file. Because files are opened relative to _CWD$, this can be useful for programs that expect to open e.g. graphical or sound assets, but problematic for programs that want to interpret paths supplied by the user as relative to the user’s current directory. In the latter case, add a ‘CHDIR _STARTDIR$’ to the top of the program. This will change back to the working directory inherited from the environment.

Availability

Example(s)

Showcasing QB64 path functions:


$CONSOLE:ONLY
_DEST _CONSOLE
SHELL "cd"
PRINT _CWD$
PRINT _STARTDIR$
SYSTEM 

See Also