From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Supported in Run BASIC


The DefaultDir$ is a JustBASIC special global variable. It contains the name of the directory in which the currently running JB program is located. Being global, it can be seen or modified in any subroutine or function. (Directory means the same as folder).
The format is "drive:\dir1", or "drive:\dir1\dir2" etc. There is no backslash appended to the DefaultDir$ variable.
unless you are in a root folder, in that case it would be c:\ etc.
See also the FILES statement.


  1. print DefaultDir$


Using a filename without path information assumes that the file is located in the DefaultDir$.
It looks like you can freely change DefaultDir$ variable. After changing, opening files without path will be in that changed directory.
FILEDIALOG opens in DefaultDir$. So, by changing it, you can change starting folder of FILEDIALOG (see example).
RUN command is not affected by changing DefaultDir$
NAME command is not affected by changing DefaultDir$
If you are not sure of the full path of your DefaultDir$, run the program in the debugger and check the "Show default variables" checkbox. Or, issue a "print DefaultDir$" command.
DefaultDir$ is a reserved word and cannot be used as a user-defined variable in a program.
At least under XP SP3 doubling backslashes (\) in a DefaultDir$ or path in OPEN statement seems to be ignored (it just works, no error). So even if your program sits in a root folder, open DefaultDir$ + "\myfile.txt" will still work.


' To open a file in the default directory, do this:
    open "myfile.txt" for append as #1
    #1 "Sample"
    close #1

' Or, do this, and be sure to include the backslash:
    open DefaultDir$ + "\myfile.txt" for append as #1
    #1 "Another sample"
    close #1
'demo of changing starting directory of FileDialog
print "DefaultDir$ is " ;DefaultDir$
print "See filedialog open in DefaultDir$"
filedialog "Open a file", "*.*", res$
if res$<>"" then print res$ else print "cancelled"

print "Now change DefaultDir$ to"
print DefaultDir$
print "If this folder exists, then fileDialog will open in that folder"
filedialog "Open a file", "*.*", res$
if res$<>"" then print res$ else print "cancelled"

Useful Procedures

' Place a useful function using this keyword here