1/* 2** IterateDirectory: File Manager directory iterator routines. 3** 4** by Jim Luther 5** 6** File: IterateDirectory.h 7** 8** Copyright (c) 1995-1998 Jim Luther and Apple Computer, Inc. 9** All rights reserved. 10** 11** You may incorporate this sample code into your applications without 12** restriction, though the sample code has been provided "AS IS" and the 13** responsibility for its operation is 100% yours. 14** 15** IterateDirectory is designed to drop into the MoreFiles sample code 16** library I wrote while in Apple Developer Technical Support 17*/ 18 19#ifndef __RECURSEDIRECTORY__ 20#define __RECURSEDIRECTORY__ 21 22#include <Types.h> 23#include <Files.h> 24 25 26#ifdef __cplusplus 27extern "C" { 28#endif 29 30 31/*****************************************************************************/ 32 33pascal OSErr RecurseDirectory(short vRefNum, 34 long dirID, 35 ConstStr255Param name, 36 unsigned short maxLevels ); 37/* Iterate (scan) through a directory's content. 38 The IterateDirectory function performs a recursive iteration (scan) of 39 the specified directory and calls your IterateFilterProc function once 40 for each file and directory found. 41 42 The maxLevels parameter lets you control how deep the recursion goes. 43 If maxLevels is 1, IterateDirectory only scans the specified directory; 44 if maxLevels is 2, IterateDirectory scans the specified directory and 45 one subdirectory below the specified directory; etc. Set maxLevels to 46 zero to scan all levels. 47 48 The yourDataPtr parameter can point to whatever data structure you might 49 want to access from within the IterateFilterProc. 50 51 vRefNum input: Volume specification. 52 dirID input: Directory ID. 53 name input: Pointer to object name, or nil when dirID 54 specifies a directory that's the object. 55 maxLevels input: Maximum number of directory levels to scan or 56 zero to scan all directory levels. 57 iterateFilter input: A pointer to the routine you want called once 58 for each file and directory found by 59 IterateDirectory. 60 yourDataPtr input: A pointer to whatever data structure you might 61 want to access from within the IterateFilterProc. 62 63 Result Codes 64 noErr 0 No error 65 nsvErr -35 No such volume 66 ioErr -36 I/O error 67 bdNamErr -37 Bad filename 68 fnfErr -43 File not found 69 paramErr -50 No default volume or iterateFilter was NULL 70 dirNFErr -120 Directory not found or incomplete pathname 71 or a file was passed instead of a directory 72 afpAccessDenied -5000 User does not have the correct access 73 afpObjectTypeErr -5025 Directory not found or incomplete pathname 74 75 __________ 76 77 See also: RecurseFilterProcPtr, FSpRecurseDirectory 78*/ 79 80/*****************************************************************************/ 81 82pascal OSErr FSpRecurseDirectory(const FSSpec *spec, 83 unsigned short maxLevels); 84/* Iterate (scan) through a directory's content. 85 The FSpIterateDirectory function performs a recursive iteration (scan) 86 of the specified directory and calls your IterateFilterProc function once 87 for each file and directory found. 88 89 The maxLevels parameter lets you control how deep the recursion goes. 90 If maxLevels is 1, FSpIterateDirectory only scans the specified directory; 91 if maxLevels is 2, FSpIterateDirectory scans the specified directory and 92 one subdirectory below the specified directory; etc. Set maxLevels to 93 zero to scan all levels. 94 95 The yourDataPtr parameter can point to whatever data structure you might 96 want to access from within the IterateFilterProc. 97 98 spec input: An FSSpec record specifying the directory to scan. 99 maxLevels input: Maximum number of directory levels to scan or 100 zero to scan all directory levels. 101 iterateFilter input: A pointer to the routine you want called once 102 for each file and directory found by 103 FSpIterateDirectory. 104 yourDataPtr input: A pointer to whatever data structure you might 105 want to access from within the IterateFilterProc. 106 107 Result Codes 108 noErr 0 No error 109 nsvErr -35 No such volume 110 ioErr -36 I/O error 111 bdNamErr -37 Bad filename 112 fnfErr -43 File not found 113 paramErr -50 No default volume or iterateFilter was NULL 114 dirNFErr -120 Directory not found or incomplete pathname 115 afpAccessDenied -5000 User does not have the correct access 116 afpObjectTypeErr -5025 Directory not found or incomplete pathname 117 118 __________ 119 120 See also: RecurseFilterProcPtr, RecurseDirectory 121*/ 122 123 124 125/*****************************************************************************/ 126 127 128 129#endif /* __RECURSEDIRECTORY__ */ 130