[comp.sys.mac.programmer] Setting a default folder

elkins@topaz.rutgers.edu (George Elkins) (11/11/88)

Does anybody have any idea how to code a "Set Directory" command
on the Mac?  I would like to perform a command similar to the
"cd" command in Unix, but with a dialog box similar to the Save As
command, but without a Save button, and with a Set Directory button
that can be applied to a selected directory.  It will be essentially
like a Save As dialog box but only folders (directorys) will show
in the list.

I need this to be able to batch process all files within
a directory of a certain type (e.g. all PICT files) after the
appropriate folder has been set.

Parden my ignorance if this is trivial.

Thanks,
George Elkins

holland@m2.csc.ti.com (Fred Hollander) (11/14/88)

In article <Nov.10.21.44.47.1988.6348@topaz.rutgers.edu> elkins@topaz.rutgers.edu (George Elkins) writes:
>
>Does anybody have any idea how to code a "Set Directory" command
>on the Mac?  I would like to perform a command similar to the
>"cd" command in Unix, but with a dialog box similar to the Save As
>command, but without a Save button, and with a Set Directory button
>that can be applied to a selected directory.  It will be essentially
>like a Save As dialog box but only folders (directorys) will show
>in the list.

I think that all you need to do is put up a standard SFGetFile dialog.  Then
do a SetVol using the vRefNum returned from the SFGetFile.

Fred Hollander
Computer Science Center
Texas Instruments, Inc.
holland%ti-csl@csnet-rela

The above statements are my own and not representative of Texas Instruments.

grae@murdu.OZ (Graeme Gerrard) (11/14/88)

> topaz.rutgers.edu wants to know about setting default directories.

From memory, what you need is to get the ioWDDirID of the
directory you want as your default. If you only know the
NAME of the directory, you can get the ioWDDirID by calling
PBHSetVol, passing a WDPBRec with the name in ioNamePtr,
ioVRefNum = 0 and ioWDDirID = 0L.
Then call PBHGetVol and with the same parameter block and it
returns the ioWDDirID of the directory you are after.
Now set the global, CurDirStore, to the ioWDDirID, and call
SFGet/PutFile. The result is a "set directory" before you get
your dialog box up.

Disclaimer: Just because this works for me, don't mean it's
going to work for you.
I can send you a SetDirectory function in C if you mail me.
-------------------------------------------
Graeme Gerrard
Faculty of Music, University of Melbourne
ARPANET: grae@murdu.oz.au
-------------------------------------------

holland@m2.csc.ti.com (Fred Hollander) (11/16/88)

In article <1479@murdu.OZ> grae@murdu.UUCP (Graeme Gerrard) writes:
>> topaz.rutgers.edu wants to know about setting default directories.
>
>From memory, what you need is to get the ioWDDirID of the
>directory you want as your default. If you only know the
>NAME of the directory, you can get the ioWDDirID by calling
>PBHSetVol, passing a WDPBRec with the name in ioNamePtr,
>ioVRefNum = 0 and ioWDDirID = 0L.

Calling PBHSetVol is dangerous as explained in Tech Note 140.  It sets the 
volume and directory separately, so subsequent calls to PBGetVol and GetVol
will return the RefNum of the root directory, not the default directory.

>Then call PBHGetVol and with the same parameter block and it
>returns the ioWDDirID of the directory you are after.
>Now set the global, CurDirStore, to the ioWDDirID, and call
>SFGet/PutFile. The result is a "set directory" before you get
>your dialog box up.

I think he wanted to use the dialog to set the directory.  SFGetFile will
put up the standard file dialog and return the RefNum of the chosen directory
(SFReply.vRefNum).  Use this value to set the default directory using SetVol.

>
>Disclaimer: Just because this works for me, don't mean it's
>going to work for you.
>I can send you a SetDirectory function in C if you mail me.
>-------------------------------------------
>Graeme Gerrard
>Faculty of Music, University of Melbourne
>ARPANET: grae@murdu.oz.au
>-------------------------------------------

Fred Hollander
Computer Science Center
Texas Instruments, Inc.
holland%ti-csl@csnet-rela

The above statements are my own and not representative of Texas Instruments.

darin@Apple.COM (Darin Adler) (11/16/88)

In article <1479@murdu.OZ> grae@murdu.UUCP (Graeme Gerrard) writes:
> > topaz.rutgers.edu wants to know about setting default directories.
> 
> From memory, what you need is to get the ioWDDirID of the
> directory you want as your default. If you only know the
> NAME of the directory, you can get the ioWDDirID by calling
> PBHSetVol, passing a WDPBRec with the name in ioNamePtr,
> ioVRefNum = 0 and ioWDDirID = 0L.
> Then call PBHGetVol and with the same parameter block and it
> returns the ioWDDirID of the directory you are after.
> Now set the global, CurDirStore, to the ioWDDirID, and call
> SFGet/PutFile. The result is a "set directory" before you get
> your dialog box up.

In general, this advice is good. However, a PBHSetVol followed by a
PBHGetVol is *not* a good way to get the dirID from a working
directory (or name of a directory). If you have the name of a
directory and need the dirID, you can use the GetCatInfo call to get
it. Pass the name of the the file in ioNamePtr, and set ioFDirIndex
to 0. The dirID will come back in ioDrDirID. Note that you should also
check if it is a directory rather than a file by looking at bit 4 of
ioFlAttrib.

Then you should set the low memory global SFSaveDisk to -vRefNum, where
vRefNum is the volume reference number of the disk which the directory
is on and set CurDirStore the dirID (from ioDrDirID).

For more information see page IV-125 of Inside Macintosh ("CInfoPBRec"),
page IV-155 of Inside Macintosh ("PBGetCatInfo"), Technical Note #69
("Setting ioFDirIndex in PBGetCatInfo Calls"), Technical Note #80 ("Standard
File Tips"), and Technical Note #140 ("Why PBHSetVol is Dangerous").
--
Darin Adler					       AppleLink: Adler4
UUCP: {sun,voder,nsc,mtxinu,dual}!apple!darin	  CSNET: darin@Apple.com