FB II Compiler
Display a folder selection dialog
A while ago there was some discussion about how to do these things:
* Display a "folder-selection" dialog;
* Temporarily override the user's preferences as set in the "General Controls" control panel, so that the program can specify which folder is to be initially displayed in the dialog.
I've created a nice DCOD called "ChooseFolder" which does these things. It's easy to plug into your programs. You can call it with an "_fOpen" option (to select an existing folder), or an "_fSave" option (to select an existing folder or create a new one). You can either honor the user's "initial folder" preference as set in the "General Controls" panel, or you can force a particular folder to be the initially-displayed one.
It's available (with documentation) at the following URL:
Thank you very much for providing this fantastic function. It works great.
I do have a couple of problems, please excuse my ignorance. I do not know how to use vRefNum% and dirID& returned by your function to access files.
Rick wrote in the Read Me file:
<< IMPORTANT: Remember that, when the user selects a folder, the value that you get back in vRefNum% will be a Volume Reference Number (not a Working Directory Reference Number), and the value you get back in dirID& will be a valid Directory ID. This is true regardless of what you initially put into these variables. >>
Well how do you get the Working Directory Reference Number so you can open a file in the selected folder. Also how do you get the name of the folder that was selected.
Rick Brown wrote:
<< Once you've got the volume number (ioFCBVRefNum) and the file's parent directory ID (ioFCBParID), you can use those to generate a working directory reference number--if you _really_ want to do that. It's easy enough to work in FB without using working directory ref. numbers, and they are "disrecommended" by Apple. >>
How can you avoid using working directory reference numbers? I think the Open and Save commands need it or a full path name to access files.
You can OPEN a file without having a w.d.ref.num, if you use the PARENTID statement, as follows:
PARENTID = dirID&
OPEN "I", #1, filename$, recLen, volumeRefNum%
when you use PARENTID to set the directory ID just before you OPEN, then you can use a (true) volume reference number in the OPEN statement.
To get the name of the folder that was selected, one way that comes to mind is to use FN GETCATINFO.
LOCAL FN GetFolderName$(volumeRefNum%, dirID&)
DIM pb.108, folderName$
pb.ioNamePtr& = @folderName$
pb.ioVRefNum% = volumeRefNum%
pb.ioDirID& = dirID&
pb.ioFDirIndex% = -1 'Return info about the folder
OSErr = FN GETCATINFO(@pb)
END FN = folderName$