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); };
earleh@eleazar.dartmouth.edu (Earle R. Horton) (07/14/89)
In article <84039@ti-csl.csc.ti.com> leeke@m2.UUCP (Steve Leeke) writes: >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? The solution is simple. Instead of saving the working directory reference number, save permanent information which can be used to find the place where the file is. Save the volume reference number and the directory ID of the folder where the file was found. You can use PBGetWDInfo or the new GetWDInfo glue for this purpose, once you have the working directory reference number. Then close the working directory, since you won't need it until you look for that file again. If anyone tells you to save the pathname, don't listen. Earle R. Horton "People forget how fast you did a job, but they remember how well you did it." Salada Tag Lines
dorner@pequod.cso.uiuc.edu (Steve Dorner) (07/14/89)
In article <84039@ti-csl.csc.ti.com> leeke@m2.UUCP (Steve Leeke) writes: >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? Save the DirId instead of the vRefNum. You can always open it as a working directory later, when you actually intend to USE it. The DirId is also unique forever for a particular directory on a particular volume. -- Steve Dorner, U of Illinois Computing Services Office Internet: s-dorner@uiuc.edu UUCP: {convex,uunet}!uiucuxc!dorner IfUMust: (217) 244-1765
leeke@m2.csc.ti.com (Steve Leeke) (07/15/89)
In article <1471@garcon.cso.uiuc.edu> dorner@pequod.cso.uiuc.edu (Steve Dorner) writes: >In article <84039@ti-csl.csc.ti.com> leeke@m2.UUCP (Steve Leeke) writes: >>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? > >Save the DirId instead of the vRefNum. You can always open it as a working >directory later, when you actually intend to USE it. The DirId is also >unique forever for a particular directory on a particular volume. >-- >Steve Dorner, U of Illinois Computing Services Office >Internet: s-dorner@uiuc.edu UUCP: {convex,uunet}!uiucuxc!dorner >IfUMust: (217) 244-1765 Steve & Earle: This is exactly what I wound up doing and it works great. Many thanks! Steve Leeke
larryh@tekgvs.LABS.TEK.COM (Larry Hutchinson) (07/18/89)
In article <14409@dartvax.Dartmouth.EDU> earleh@eleazar.dartmouth.edu (Earle R. Horton) writes: > > The solution is simple. Instead of saving the working directory >reference number, save permanent information which can be used to find >the place where the file is. Save the volume reference number and the >directory ID of the folder where the file was found. You can use . . > If anyone tells you to save the pathname, don't listen. But but but.. Didn't we discuss this at length about a year ago? I beleive that the upshot is that one can not use directory IDs for uses that are long term because both AU/X and AppleShare fake them up for the current boot only. Has this changed?? Does anyone remember that discussion? P.S. Let's move this to comp.sys.mac.programmer where it belongs. Larry Hutchinson, Tektronix, Inc. PO Box 500, MS 50-383, Beaverton, OR 97077 UUCP: [uunet|ucbvax|decvax|hplabs]!tektronix!tekgvs!larryh ARPA: larryh%tekgvs.LABS.TEK.COM@RELAY.CS.NET CSNet: larryh@tekgvs.LABS.TEK.COM
chaffee@uvm-gen.UUCP (Alex D. Chaffee,231 Votey,,6581273) (07/18/89)
From article <84039@ti-csl.csc.ti.com>, by leeke@m2.csc.ti.com (Steve Leeke): > 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 How about... int scavengeDirectory(dirName,vRefNum,wPtr) ... { Boolean DeleteWD = true; ... result = 0; ... do { ... } else { if (dirRec.ioFlFndrInfo.fdType == XPRCSignature) { /* Save vRefNum */ /* return the vRefNum if it was found, else return 0 */ result = dirWDRec.vRefNum; DeleteWD = false; }; ... } while (err != fnfErr && !result); /* don't delete the WD if it contains our file */ if (DeleteWD) PBCloseWD(&dirWDRec,false); }; return(result); }; Of course, you could go one step further... if (!result) PBCloseWD(...) and do away with DeleteWD. Alex Chaffee chaffee@emily.uvm.edu ____________________________