BB___DefaultDir

=DefaultDir$= toc

Description
> 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.

Usage

 * 1) print DefaultDir$

Hints

 * 1) Using a filename without path information assumes that the file is located in the DefaultDir$.
 * 2) It looks like you can freely change DefaultDir$ variable. After changing, opening files without path will be in that changed directory.
 * 3) FILEDIALOG opens in DefaultDir$. So, by changing it, you can change starting folder of FILEDIALOG (see example).
 * 4) RUN command is not affected by changing DefaultDir$
 * 5) NAME command is not affected by changing DefaultDir$
 * 6) 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.
 * 7) DefaultDir$ is a reserved word and cannot be used as a user-defined variable in a program.
 * 8) 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,  will still work.

Example
code format="lb" ' 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 code

code format="lb" '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" DefaultDir$=DefaultDir$+"\media" 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" code

Useful Functions
code format="lb" Place a useful function using this command here code