This article is from the Mac Programming FAQ, by Jon Watte firstname.lastname@example.org with numerous contributions by others.
Use GetWDInfo, which is declared as:
Pascal OSErr GetWDInfo ( short wdRefNum , short * vRefNum , long * parID
, OSType * procID ) ;
The procID parameter must be non-NULL and point to an OSType variable,
but the value of that variable can and should be ignored.
It is recommended that, as soon as you get your hands on a wdRefNum, for
instance from SFGetFile, you directly convert it into a vRefNum/parID
pair and always use the latter to reference the folder.