2 ** Apple Macintosh Developer Technical Support
4 ** DirectoryCopy: A robust, general purpose directory copy routine.
6 ** by Jim Luther, Apple Developer Technical Support Emeritus
8 ** File: DirectoryCopy.h
10 ** Copyright © 1992-1998 Apple Computer, Inc.
11 ** All rights reserved.
13 ** You may incorporate this sample code into your applications without
14 ** restriction, though the sample code has been provided "AS IS" and the
15 ** responsibility for its operation is 100% yours. However, what you are
16 ** not permitted to do is to redistribute the source as "DSC Sample Code"
17 ** after having made changes. If you're going to re-distribute the source,
18 ** we require that you make it clear in the source that the code was
19 ** descended from Apple Sample Code, but that you've made changes.
22 #ifndef __DIRECTORYCOPY__
23 #define __DIRECTORYCOPY__
34 /*****************************************************************************/
38 getNextItemOp
= 1, /* couldn't access items in this directory - no access privileges */
39 copyDirCommentOp
= 2, /* couldn't copy directory's Finder comment */
40 copyDirAccessPrivsOp
= 3, /* couldn't copy directory's AFP access privileges */
41 copyDirFMAttributesOp
= 4, /* couldn't copy directory's File Manager attributes */
42 dirCreateOp
= 5, /* couldn't create destination directory */
43 fileCopyOp
= 6 /* couldn't copy file */
46 /*****************************************************************************/
48 typedef pascal Boolean (*CopyErrProcPtr
) (OSErr error
,
49 short failedOperation
,
52 ConstStr255Param srcName
,
55 ConstStr255Param dstName
);
56 /* ¦ Prototype for the CopyErrProc function DirectoryCopy calls.
57 This is the prototype for the CopyErrProc function DirectoryCopy
58 calls if an error condition is detected sometime during the copy. If
59 CopyErrProc returns false, then DirectoryCopy attempts to continue with
60 the directory copy operation. If CopyErrProc returns true, then
61 DirectoryCopy stops the directory copy operation.
63 error input: The error result code that caused CopyErrProc to
65 failedOperation input: The operation that returned an error to
67 srcVRefNum input: Source volume specification.
68 srcDirID input: Source directory ID.
69 srcName input: Source file or directory name, or nil if
70 srcDirID specifies the directory.
71 dstVRefNum input: Destination volume specification.
72 dstDirID input: Destination directory ID.
73 dstName input: Destination file or directory name, or nil if
74 dstDirID specifies the directory.
78 Also see: FilteredDirectoryCopy, FSpFilteredDirectoryCopy, DirectoryCopy, FSpDirectoryCopy
81 #define CallCopyErrProc(userRoutine, error, failedOperation, srcVRefNum, srcDirID, srcName, dstVRefNum, dstDirID, dstName) \
82 (*(userRoutine))((error), (failedOperation), (srcVRefNum), (srcDirID), (srcName), (dstVRefNum), (dstDirID), (dstName))
84 /*****************************************************************************/
86 typedef pascal Boolean (*CopyFilterProcPtr
) (const CInfoPBRec
* const cpbPtr
);
88 /* ¦ Prototype for the CopyFilterProc function.
89 This is the prototype for the CopyFilterProc function called by
90 FilteredDirectoryCopy and GetLevelSize. If true is returned,
91 the file/folder is included in the copy, otherwise it is excluded.
93 pb input: Points to the CInfoPBRec for the item under consideration.
97 Also see: FilteredDirectoryCopy, FSpFilteredDirectoryCopy
100 #define CallCopyFilterProc(userRoutine, cpbPtr) (*(userRoutine))((cpbPtr))
102 /*****************************************************************************/
104 pascal OSErr
FilteredDirectoryCopy(short srcVRefNum
,
106 ConstStr255Param srcName
,
109 ConstStr255Param dstName
,
113 CopyErrProcPtr copyErrHandler
,
114 CopyFilterProcPtr copyFilterProc
);
115 /* ¦ Make a copy of a directory structure in a new location with item filtering.
116 The FilteredDirectoryCopy function makes a copy of a directory
117 structure in a new location. If copyBufferPtr <> NIL, it points to
118 a buffer of copyBufferSize that is used to copy files data. The
119 larger the supplied buffer, the faster the copy. If
120 copyBufferPtr = NIL, then this routine allocates a buffer in the
121 application heap. If you pass a copy buffer to this routine, make
122 its size a multiple of 512 ($200) bytes for optimum performance.
124 The optional copyFilterProc parameter lets a routine you define
125 decide what files or directories are copied to the destination.
127 FilteredDirectoryCopy normally creates a new directory *in* the
128 specified destination directory and copies the source directory's
129 content into the new directory. However, if root parent directory
130 (fsRtParID) is passed as the dstDirID parameter and NULL is
131 passed as the dstName parameter, DirectoryCopy renames the
132 destination volume to the source directory's name (truncating
133 if the name is longer than 27 characters) and copies the source
134 directory's content into the destination volume's root directory.
135 This special case is supported by FilteredDirectoryCopy, but
136 not by FSpFilteredDirectoryCopy since with FSpFilteredDirectoryCopy,
137 the dstName parameter can not be NULL.
139 srcVRefNum input: Source volume specification.
140 srcDirID input: Source directory ID.
141 srcName input: Source directory name, or nil if
142 srcDirID specifies the directory.
143 dstVRefNum input: Destination volume specification.
144 dstDirID input: Destination directory ID.
145 dstName input: Destination directory name, or nil if
146 dstDirID specifies the directory.
147 copyBufferPtr input: Points to a buffer of copyBufferSize that
148 is used the i/o buffer for the copy or
149 nil if you want DirectoryCopy to allocate its
150 own buffer in the application heap.
151 copyBufferSize input: The size of the buffer pointed to
153 preflight input: If true, DirectoryCopy makes sure there are
154 enough allocation blocks on the destination
155 volume to hold the directory's files before
157 copyErrHandler input: A pointer to the routine you want called if an
158 error condition is detected during the copy, or
159 nil if you don't want to handle error conditions.
160 If you don't handle error conditions, the first
161 error will cause the copy to quit and
162 DirectoryCopy will return the error.
163 Error handling is recommended...
164 copyFilterProc input: A pointer to the filter routine you want called
165 for each item in the source directory, or NULL
166 if you don't want to filter.
170 readErr Ð19 Driver does not respond to read requests
171 writErr Ð20 Driver does not respond to write requests
172 badUnitErr Ð21 Driver reference number does not
174 unitEmptyErr Ð22 Driver reference number specifies a
175 nil handle in unit table
176 abortErr Ð27 Request aborted by KillIO
177 notOpenErr Ð28 Driver not open
178 dskFulErr -34 Destination volume is full
179 nsvErr -35 No such volume
181 bdNamErr -37 Bad filename
182 tmfoErr -42 Too many files open
183 fnfErr -43 Source file not found, or destination
184 directory does not exist
185 wPrErr -44 Volume locked by hardware
186 fLckdErr -45 File is locked
187 vLckdErr -46 Destination volume is read-only
188 fBsyErr -47 The source or destination file could
189 not be opened with the correct access
191 dupFNErr -48 Destination file already exists
192 opWrErr -49 File already open for writing
193 paramErr -50 No default volume or function not
195 permErr -54 File is already open and cannot be opened using specified deny modes
196 memFullErr -108 Copy buffer could not be allocated
197 dirNFErr -120 Directory not found or incomplete pathname
198 wrgVolTypErr -123 Function not supported by volume
199 afpAccessDenied -5000 User does not have the correct access
200 afpDenyConflict -5006 The source or destination file could
201 not be opened with the correct access
203 afpObjectTypeErr -5025 Source is a directory, directory not found
204 or incomplete pathname
208 Also see: CopyErrProcPtr, CopyFilterProcPtr, FSpFilteredDirectoryCopy,
209 DirectoryCopy, FSpDirectoryCopy, FileCopy, FSpFileCopy
212 /*****************************************************************************/
214 pascal OSErr
FSpFilteredDirectoryCopy(const FSSpec
*srcSpec
,
215 const FSSpec
*dstSpec
,
219 CopyErrProcPtr copyErrHandler
,
220 CopyFilterProcPtr copyFilterProc
);
221 /* ¦ Make a copy of a directory structure in a new location with item filtering.
222 The FSpFilteredDirectoryCopy function makes a copy of a directory
223 structure in a new location. If copyBufferPtr <> NIL, it points to
224 a buffer of copyBufferSize that is used to copy files data. The
225 larger the supplied buffer, the faster the copy. If
226 copyBufferPtr = NIL, then this routine allocates a buffer in the
227 application heap. If you pass a copy buffer to this routine, make
228 its size a multiple of 512 ($200) bytes for optimum performance.
230 The optional copyFilterProc parameter lets a routine you define
231 decide what files or directories are copied to the destination.
233 srcSpec input: An FSSpec record specifying the directory to copy.
234 dstSpec input: An FSSpec record specifying destination directory
236 copyBufferPtr input: Points to a buffer of copyBufferSize that
237 is used the i/o buffer for the copy or
238 nil if you want DirectoryCopy to allocate its
239 own buffer in the application heap.
240 copyBufferSize input: The size of the buffer pointed to
242 preflight input: If true, FSpDirectoryCopy makes sure there are
243 enough allocation blocks on the destination
244 volume to hold the directory's files before
246 copyErrHandler input: A pointer to the routine you want called if an
247 error condition is detected during the copy, or
248 nil if you don't want to handle error conditions.
249 If you don't handle error conditions, the first
250 error will cause the copy to quit and
251 DirectoryCopy will return the error.
252 Error handling is recommended...
253 copyFilterProc input: A pointer to the filter routine you want called
254 for each item in the source directory, or NULL
255 if you don't want to filter.
259 readErr Ð19 Driver does not respond to read requests
260 writErr Ð20 Driver does not respond to write requests
261 badUnitErr Ð21 Driver reference number does not
263 unitEmptyErr Ð22 Driver reference number specifies a
264 nil handle in unit table
265 abortErr Ð27 Request aborted by KillIO
266 notOpenErr Ð28 Driver not open
267 dskFulErr -34 Destination volume is full
268 nsvErr -35 No such volume
270 bdNamErr -37 Bad filename
271 tmfoErr -42 Too many files open
272 fnfErr -43 Source file not found, or destination
273 directory does not exist
274 wPrErr -44 Volume locked by hardware
275 fLckdErr -45 File is locked
276 vLckdErr -46 Destination volume is read-only
277 fBsyErr -47 The source or destination file could
278 not be opened with the correct access
280 dupFNErr -48 Destination file already exists
281 opWrErr -49 File already open for writing
282 paramErr -50 No default volume or function not
284 permErr -54 File is already open and cannot be opened using specified deny modes
285 memFullErr -108 Copy buffer could not be allocated
286 dirNFErr -120 Directory not found or incomplete pathname
287 wrgVolTypErr -123 Function not supported by volume
288 afpAccessDenied -5000 User does not have the correct access
289 afpDenyConflict -5006 The source or destination file could
290 not be opened with the correct access
292 afpObjectTypeErr -5025 Source is a directory, directory not found
293 or incomplete pathname
297 Also see: CopyErrProcPtr, CopyFilterProcPtr, FilteredDirectoryCopy,
298 DirectoryCopy, FSpDirectoryCopy, FileCopy, FSpFileCopy
301 /*****************************************************************************/
303 pascal OSErr
DirectoryCopy(short srcVRefNum
,
305 ConstStr255Param srcName
,
308 ConstStr255Param dstName
,
312 CopyErrProcPtr copyErrHandler
);
313 /* ¦ Make a copy of a directory structure in a new location.
314 The DirectoryCopy function makes a copy of a directory structure in a
315 new location. If copyBufferPtr <> NIL, it points to a buffer of
316 copyBufferSize that is used to copy files data. The larger the
317 supplied buffer, the faster the copy. If copyBufferPtr = NIL, then this
318 routine allocates a buffer in the application heap. If you pass a
319 copy buffer to this routine, make its size a multiple of 512
320 ($200) bytes for optimum performance.
322 DirectoryCopy normally creates a new directory *in* the specified
323 destination directory and copies the source directory's content into
324 the new directory. However, if root parent directory (fsRtParID)
325 is passed as the dstDirID parameter and NULL is passed as the
326 dstName parameter, DirectoryCopy renames the destination volume to
327 the source directory's name (truncating if the name is longer than
328 27 characters) and copies the source directory's content into the
329 destination volume's root directory. This special case is supported
330 by DirectoryCopy, but not by FSpDirectoryCopy since with
331 FSpDirectoryCopy, the dstName parameter can not be NULL.
333 srcVRefNum input: Source volume specification.
334 srcDirID input: Source directory ID.
335 srcName input: Source directory name, or nil if
336 srcDirID specifies the directory.
337 dstVRefNum input: Destination volume specification.
338 dstDirID input: Destination directory ID.
339 dstName input: Destination directory name, or nil if
340 dstDirID specifies the directory.
341 copyBufferPtr input: Points to a buffer of copyBufferSize that
342 is used the i/o buffer for the copy or
343 nil if you want DirectoryCopy to allocate its
344 own buffer in the application heap.
345 copyBufferSize input: The size of the buffer pointed to
347 preflight input: If true, DirectoryCopy makes sure there are
348 enough allocation blocks on the destination
349 volume to hold the directory's files before
351 copyErrHandler input: A pointer to the routine you want called if an
352 error condition is detected during the copy, or
353 nil if you don't want to handle error conditions.
354 If you don't handle error conditions, the first
355 error will cause the copy to quit and
356 DirectoryCopy will return the error.
357 Error handling is recommended...
361 readErr Ð19 Driver does not respond to read requests
362 writErr Ð20 Driver does not respond to write requests
363 badUnitErr Ð21 Driver reference number does not
365 unitEmptyErr Ð22 Driver reference number specifies a
366 nil handle in unit table
367 abortErr Ð27 Request aborted by KillIO
368 notOpenErr Ð28 Driver not open
369 dskFulErr -34 Destination volume is full
370 nsvErr -35 No such volume
372 bdNamErr -37 Bad filename
373 tmfoErr -42 Too many files open
374 fnfErr -43 Source file not found, or destination
375 directory does not exist
376 wPrErr -44 Volume locked by hardware
377 fLckdErr -45 File is locked
378 vLckdErr -46 Destination volume is read-only
379 fBsyErr -47 The source or destination file could
380 not be opened with the correct access
382 dupFNErr -48 Destination file already exists
383 opWrErr -49 File already open for writing
384 paramErr -50 No default volume or function not
386 permErr -54 File is already open and cannot be opened using specified deny modes
387 memFullErr -108 Copy buffer could not be allocated
388 dirNFErr -120 Directory not found or incomplete pathname
389 wrgVolTypErr -123 Function not supported by volume
390 afpAccessDenied -5000 User does not have the correct access
391 afpDenyConflict -5006 The source or destination file could
392 not be opened with the correct access
394 afpObjectTypeErr -5025 Source is a directory, directory not found
395 or incomplete pathname
399 Also see: CopyErrProcPtr, FSpDirectoryCopy, FilteredDirectoryCopy,
400 FSpFilteredDirectoryCopy, FileCopy, FSpFileCopy
403 /*****************************************************************************/
405 pascal OSErr
FSpDirectoryCopy(const FSSpec
*srcSpec
,
406 const FSSpec
*dstSpec
,
410 CopyErrProcPtr copyErrHandler
);
411 /* ¦ Make a copy of a directory structure in a new location.
412 The FSpDirectoryCopy function makes a copy of a directory structure in a
413 new location. If copyBufferPtr <> NIL, it points to a buffer of
414 copyBufferSize that is used to copy files data. The larger the
415 supplied buffer, the faster the copy. If copyBufferPtr = NIL, then this
416 routine allocates a buffer in the application heap. If you pass a
417 copy buffer to this routine, make its size a multiple of 512
418 ($200) bytes for optimum performance.
420 srcSpec input: An FSSpec record specifying the directory to copy.
421 dstSpec input: An FSSpec record specifying destination directory
423 copyBufferPtr input: Points to a buffer of copyBufferSize that
424 is used the i/o buffer for the copy or
425 nil if you want DirectoryCopy to allocate its
426 own buffer in the application heap.
427 copyBufferSize input: The size of the buffer pointed to
429 preflight input: If true, FSpDirectoryCopy makes sure there are
430 enough allocation blocks on the destination
431 volume to hold the directory's files before
433 copyErrHandler input: A pointer to the routine you want called if an
434 error condition is detected during the copy, or
435 nil if you don't want to handle error conditions.
436 If you don't handle error conditions, the first
437 error will cause the copy to quit and
438 DirectoryCopy will return the error.
439 Error handling is recommended...
443 readErr Ð19 Driver does not respond to read requests
444 writErr Ð20 Driver does not respond to write requests
445 badUnitErr Ð21 Driver reference number does not
447 unitEmptyErr Ð22 Driver reference number specifies a
448 nil handle in unit table
449 abortErr Ð27 Request aborted by KillIO
450 notOpenErr Ð28 Driver not open
451 dskFulErr -34 Destination volume is full
452 nsvErr -35 No such volume
454 bdNamErr -37 Bad filename
455 tmfoErr -42 Too many files open
456 fnfErr -43 Source file not found, or destination
457 directory does not exist
458 wPrErr -44 Volume locked by hardware
459 fLckdErr -45 File is locked
460 vLckdErr -46 Destination volume is read-only
461 fBsyErr -47 The source or destination file could
462 not be opened with the correct access
464 dupFNErr -48 Destination file already exists
465 opWrErr -49 File already open for writing
466 paramErr -50 No default volume or function not
468 permErr -54 File is already open and cannot be opened using specified deny modes
469 memFullErr -108 Copy buffer could not be allocated
470 dirNFErr -120 Directory not found or incomplete pathname
471 wrgVolTypErr -123 Function not supported by volume
472 afpAccessDenied -5000 User does not have the correct access
473 afpDenyConflict -5006 The source or destination file could
474 not be opened with the correct access
476 afpObjectTypeErr -5025 Source is a directory, directory not found
477 or incomplete pathname
481 Also see: CopyErrProcPtr, DirectoryCopy, FilteredDirectoryCopy,
482 FSpFilteredDirectoryCopy, FileCopy, FSpFileCopy
485 /*****************************************************************************/
491 #include "optimend.h"
493 #endif /* __DIRECTORYCOPY__ */