[comp.sys.mac.programmer] Saving vRefNum's

leeke@m2.csc.ti.com (Steve Leeke) (07/14/89)

I would like to be able to recursively scavange a directory for a
certain type of file and save the vRefNum when a file of a certain
type is found.  I've included to code I'm using by it seems to cause
problems since the working directory is closed after I save the
vRefNum, but if I leave it open I wind up with too many working
directories open.  Any suggestions?

Thanks,

Steve Leeke
leeke@m2.csc.ti.com


/* - */
Boolean scavengeDirectory(dirName,vRefNum,wPtr)
StringPtr	dirName;
INT		vRefNum;
WindowPtr	wPtr;
/* - */
{
	OSErr		err;
	Str255		fileName;
	HFileInfo	dirRec;
	WDPBRec		dirWDRec;
	INT		index;
	Boolean		result;


	result	=	false;

	dirWDRec.ioCompletion	=	NULL;
	dirWDRec.ioNamePtr	=	dirName;

	dirWDRec.ioVRefNum	=	vRefNum;
	dirWDRec.ioWDProcID	=	0;
	dirWDRec.ioWDDirID	=	0;

	if (PBOpenWD(&dirWDRec,false) == noErr) {
	index	=	1;

	do {
		dirRec.ioCompletion	=	NULL;
		dirRec.ioNamePtr	=	fileName;
		dirRec.ioVRefNum	=	dirWDRec.ioVRefNum;
	
		dirRec.ioFDirIndex	=	index;
		dirRec.ioDirID		=	0;
	
		err	=	PBGetCatInfo((CInfoPBPtr) &dirRec,false);
	
		if (err == noErr) {
			if (((dirRec.ioFlAttrib >> 4) & 0x01) != 0) {
			/*
				We have a directory.
			*/
					
		if (scavengeDirectory(fileName,dirWDRec.ioVRefNum,wPtr)) {
			result	=	true;
			break;
		};
		} else {
			if (dirRec.ioFlFndrInfo.fdType == XPRCSignature) {
				/*	
					Save vRefNum.
				*/
				result	=	true;
			};
		};
		};
	
			index++;
		} while (err != fnfErr);

		PBCloseWD(&dirWDRec,false);
	};

	return(result);
};