OpenWD
OpenWD
Open a new working directory #include <Files.h> File Manager (PBxxx)
OsErr OpenWD( vRefNum, dirID, procID, wdRefNum); short vRefNum; volume, drive or working directory dir reference long dirID; working directory's directory ID
long procID; working dir user ref (app's signature or 0)
short *wdRefNum; newly created working directory reference number
OpenWD creates a new working directory. It is similar to PBOpenWD, but uses refNums and dirID's instead of a WDPBRec. A working directory number can be used whenever a volume reference number is required.
noErr (0) No error
tmwdoErr (-121) Too many working directories open
Notes: "Working directories" exist as a way to maintain compatibility with the
flat file system of the original Macintosh. In effect, a working directory
reference number is just a 16-bit alias for a 32-bit "hard" directory ID
and a "real" volume reference. When the File Manager sees a working
directory reference in a volume reference number (e.g., ioVRefNum of any
parameter block), it looks up the real directory number and uses that value
in finding files.
Note: This notion of a working directory is very different from that of a "current default directory", as MS-DOS and especially UNIX programmers
might assume. See SetVol for details on setting the default volume. The Standard File Package calls PBOpenWD each time the user selects a
directory (either by opening a folder or selecting from the drop-down list).
If the user then opens a file, the resulting working directory reference
number is returned in tr. vRefNum. Thus, if you use Standard File for file selection, you may never need OpenWD or PBOpenWD. Note: You can eyeball a VRefNum and see what it is: large negative numbers such as -32456 (0x8138) are used for working directories;
small negative numbers such as -1 (0xFFFF) are real volume numbers.
The system maintains a limited number of slots for tracking working
directories. It is wise to close WDs (via PBCloseWD) as soon as possible.