home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-05-06 | 1.9 KB | 60 lines | [TEXT/R*ch] |
- {------------------------------------- Scan Directory -------------------------------------}
- {This unit contains a single procedure ScanDir. Passing this a FSSpec will search all the files and}
- {folders in that directory. It calls its the searching procedure ScanSubDir recursively forr each}
- {sub directory in the initial directory until it has searched all files and folders. Add your own}
- {code at the point below where it finds individual files. Like most things this code was made}
- {possible by learning from others, I just put it all together in one unit for my own purposes and}
- {thought others might take advantage of it.}
- {}
- {Chris Owen}
- {owen-christopher@yale.edu}
- {-----------------------------------------------------------------------------------------}
- unit ScanDir;
-
- interface
-
- procedure ScanDir (firstDir: FSSpec);
-
- implementation
-
- procedure ScanDir (firstDir: FSSpec);
- var
- name: Str255;
- theCPRec: CInfoPBRec;
- theErr: OSErr;
-
- procedure ScanSubDir (theDir: longint);
- var
- index: integer;
-
- begin
- index := 1;
- repeat
- name := '';
- theCPRec.ioFDirIndex := index;
- theCPRec.ioDrDirID := theDir; {have to reset the dirnum each time through}
- theErr := PBGetCatInfo(@theCPRec, FALSE);
-
- if theErr = noErr then
- if BitTst(@theCPRec.ioFlAttrib, 3) then
- begin {If bit 4 is set then it is a folder}
- ScanSubDir(theCPRec.ioDrDirID); {call recursively to index next folder}
- theErr := 0; {eventually this returns an error so reset it}
- end
- else
- begin {else it is a file}
- {Do whatever you do when you find a file}
- end; {else}
- index := index + 1;
- until (theErr <> noErr);
- end;
-
- begin
- with theCPRec do {set up the CPRec with the vRefNum and place to store file name}
- begin
- ioNamePtr := @name;
- ioVRefNum := firstDir.vRefNum;
- end; {with}
- ScanSubDir(firstDir.parID); {search first directory, call recursively to do rest}
- end;
- end.