Microsoft KB Archive/36394

From BetaArchive Wiki
Knowledge Base


How the Macintosh QuickBASIC GetPathNames Program Works

Article ID: 36394

Article Last Modified on 11/21/2006

This article was previously published under Q36394

SUMMARY

The GetPathNames program shows how to find the full pathname of a program, the startup system folder, any open BASIC file, or any open resource file.

The GetPathNames program is located on the Macintosh QuickBASIC Version 1.00 Examples disk in the QuickBASIC Demos folder.

MORE INFORMATION

The GetPathNames program takes the file reference number of a file, and returns the full path name of the file. The file reference number may be obtained by several methods, depending on the file in question.

The SYSTEM(7) function returns the file reference number of the program source file if the program is running under the interpreter, and the file reference number of the the application when the program is compiled.

The System file's file reference number is in the system global variable SysMap at address &HA58. Using this, we can find the name of the "blessed" folder where many applications keep special configuration files. A file in this folder will always be found, no matter where the application opening the file resides.

The GetChanRefNum library routine returns the file reference number of a file opened in BASIC given the channel number. The channel number is the number specified in the OPEN statement. For example, in the statement OPEN f$ FOR INPUT AS #5, the channel number is 5.

The GetPathName subprogram uses the library routines GetFCBInfo and GetCatInfo to build the full pathname. GetFCBInfo returns information in a File Control Block that contains information about a file. GetCatInfo is similar, but returns information about a folder.

First, it passes the file reference number to the GetFCBInfo library routine. This returns the simple name of the file. This call also fills in other information in the IOPB%() array. At this point, you extract the directory id (DirID&) of the directory the file resides in, and the Volume Reference Number (VolRefNum%) of the disk volume the file is on.

The DirID& and VolRefNum% are passed to the GetCatInfo library routine to find the DirID& and name of the folder the current folder is in. This is done repeatedly for each "parent" folder until we reach the name of the volume, building up the full name of the file in question.

Additional information on the system functions used in the GetPathNames program can be found in "Inside Macintosh" Volume IV. The GetCatInfo function is discussed on page 155. The GetFCBInfo function is discussed on page 179.


Additional query words: MQuickB

Keywords: KB36394