Microsoft KB Archive/42368

From BetaArchive Wiki
Knowledge Base

OPEN with No Path Defaults to Current Folder; CHDIR Changes

Article ID: 42368

Article Last Modified on 11/21/2006

This article was previously published under Q42368


When you OPEN a data file for INPUT, random, or APPEND access in Macintosh QuickBASIC and specify no folder or disk path, QuickBASIC looks for the file in the "current folder."

In interpreted programs, the "current folder" defaults to the folder where QuickBASIC itself is running. In compiled programs, the "current folder" defaults to the folder where the compiled application is running.

You can use the CHDIR statement to change the current folder to any path, such as to the location of the data file that is being opened.


The following CHDIR statement makes all subsequent OPEN "filename" statements look in the folder called "folder1" on the disk volume called "Volume":

   CHDIR "Volume:Folder1:"
   OPEN "filename"           ' Looks for "Volume:Folder1:filename"

Note: You can also specify full pathnames for data files (such as OPEN "Volume:folder1:filename"). A disadvantage of this is that your program will not be able to find the file if it is moved somewhere else.

You may find it more flexible to use OPEN statements WITHOUT an explicit path, such as OPEN "filename". Statements of this form use the current search path, and can automatically remember a new path through the "Can't Find: <file>" dialog when run on write-enabled disks.

The "Can't Find File" dialog box displays if a data file OPENed for INPUT, APPEND, or random access is not in the current folder. This dialog lets you locate the data file in a different folder. If you successfully locate the file through this dialog, the program (compiled or interpreted) permanently remembers the default folder in the new location. (The "Disable File Not Found" option in Run Options... must be OFF for this to work.)

You can disable the "Can't Find: <file>" processing by selecting the "Disable File Not Found Dialog" option in Options... from the QuickBASIC Run menu. If this option is selected, a run-time error 53: "File Not Found" occurs on the OPEN when a file cannot be found in the current folder or with the specified full path.

Additional query words: MQuickB

Keywords: KB42368