home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 21243 < prev    next >
Encoding:
Text File  |  1993-01-11  |  3.8 KB  |  147 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!munnari.oz.au!uniwa!cujo!ncrpda.curtin.edu.au!rocky.curtin.edu.au!user
  3. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  4. Subject: Re: Getting List of files contained in folder
  5. Message-ID: <peter-120193114153@rocky.curtin.edu.au>
  6. Followup-To: comp.sys.mac.programmer
  7. Lines: 133
  8. Sender: news@ncrpda.curtin.edu.au
  9. Nntp-Posting-Host: ncrpda.curtin.edu.au
  10. Organization: NCRPDA, Curtin University
  11. References: <1993Jan11.113821.12019@wega.rz.uni-ulm.de>
  12. Date: Tue, 12 Jan 1993 03:46:37 GMT
  13.  
  14. In article <1993Jan11.113821.12019@wega.rz.uni-ulm.de>,
  15. walrath@faw.uni-ulm.de (Wayne K. Walrath) wrote:
  16. > I have been reading through the New IM-Files trying to figure this one
  17. > out: if I have a folder specification (like when I have thrown up a
  18. > dialog for the user to choose one) how can I get a list of all the files 
  19. > and folders contained in the folder?
  20.  
  21. Here's a program I wrote to list out all the THINK Pascal projects that are
  22. over 50k (so I could go thru and manually remove objects on all of them,
  23. which got me 5Meg of disk space back!  I wish Symantec would get around to
  24. releasing their utility for doing this, my old one doesn't work for
  25. v4.0.2)-:
  26.  
  27. It does a recursive scan give an volume reference number & dirID.
  28.  
  29. As Jon said, learn to love the PBGetCatInfo call, its very important (less
  30. important than learning the difference between vrn's and working directory
  31. numbers and how dirIDs fit in, but still quite important).
  32.  
  33. program Scan;
  34.  
  35.     uses
  36.         MyUtilities, MyStandardFile;
  37.  
  38.     var
  39.         path: str255;
  40.  
  41.     procedure Doit (vrn: integer; dirID: longInt; fname: str63);
  42.         var
  43.             pb: HParamBlockRec;
  44.             oe: OSErr;
  45.             rn: integer;
  46.     begin
  47.         with pb do begin
  48.             ioNamePtr := @fname;
  49.             ioVRefNum := vrn;
  50.             ioDirID := dirID;
  51.             ioFDirIndex := 0;
  52.             oe := PBGetCatInfo(@pb, false);
  53.         end;
  54.         if (oe = noErr) & (pb.ioFlFndrInfo.fdType = 'QPRJ') & (pb.ioFlRLgLen >
  55. 50000) then begin
  56.             writeln(concat(path, ':', fname));
  57.         end;
  58.     end;
  59.  
  60.     procedure WaitForEvent (sleep: integer);
  61.         var
  62.             er: EventRecord;
  63.             dummy: boolean;
  64.     begin
  65.         dummy := WaitNextEvent(everyEvent, er, sleep, nil);
  66.     end;
  67.  
  68.     procedure ScanFolders (vrn: integer; dirID: longInt);
  69.         var
  70.             pb: HParamBlockRec;
  71.             name: str63;
  72.         procedure Scan (dirID: longInt);
  73.             var
  74.                 index, len: integer;
  75.                 oe: OSErr;
  76.         begin
  77.             WaitForEvent(5);
  78.             index := 1;
  79.             repeat
  80.                 with pb do begin
  81.                     ioNamePtr := @name;
  82.                     ioVRefNum := vrn;
  83.                     ioDirID := dirID;
  84.                     ioFDirIndex := index;
  85.                     oe := PBGetCatInfo(@pb, false);
  86.                     if oe = noErr then
  87.                         if BAND(pb.ioFlAttrib, $10) = 0 then
  88.                             Doit(vrn, dirID, name)
  89.                         else begin
  90.                             len := length(path);
  91.                             path := concat(path, ':', name);
  92.                             Scan(pb.ioDirID);
  93.                             path[0] := chr(len);
  94.                         end;
  95.                     index := index + 1;
  96.                 end;
  97.             until oe <> noErr;
  98.             WaitForEvent(5);
  99.         end;
  100.     begin
  101.         Scan(dirID);
  102.     end;
  103.  
  104.     var
  105.         reply: MySFReply;
  106.         typeList: SFTypeList;
  107. begin
  108.     path := '';
  109.     ShowText;
  110.     InitUtilities;
  111. {GetFolder(nil, -1, typeList, 500, reply);}
  112.     reply.Rgood := true;
  113.     reply.RvRefNum := -1;
  114.     reply.RdirID := 2;
  115.     reply.Rfolder := true;
  116.     with reply do
  117.         if Rgood then begin
  118.             if Rfolder then
  119.                 ScanFolders(RvRefNum, RDirID)
  120.             else
  121.                 Doit(RvRefNum, RDirID, RfName);
  122.         end;
  123.     write('Finished - Click the Mouse Button');
  124.     while not Button do
  125.         WaitForEvent(15);
  126. end.
  127.  
  128. >   Is it possible to use the new Cat Search function 
  129. > available under 7.x (_FSBCatSearch or something similiar) but limit it to 
  130. > only the folder in question?
  131.  
  132. Beats me.
  133.  
  134. > I would appreciate a general explanation of how to do this, or better
  135. > still some code.
  136.  
  137. There is the code, all it does is use the ioFDirIndex field to call
  138. PBGetCatInfo successively with a larger index til it runs off the end of
  139. the folder...
  140.  
  141. Have fun,
  142.    Peter.
  143.  
  144. _______________________________________________________________________
  145. Peter N Lewis <peter@cujo.curtin.edu.au>             Ph: +61 9 368 2055
  146.