> What is the best way to recursively remove a directory and all of it's sub > directories and files, BTW I need to support 10.4 systems.
Send an Apple Event to the finder to move the parent directory to the Trash, then another Apple Event to actually empty the Trash. **** RIM SHOT! **** But seriously folks, look at "man opendir" "rewindir" and "readdir". It's a portable way to read UNIX directories as if they were regular files containing a linear array of filenames. Make sure you look at "man 3 readdir" and not "man 2 readdir". Section 3 of the man pages covers a portable standard library wrapper around the non-portable and more-complex man section 2 system call. The library call works the same on every POSIX system, but the system call is, in general, different everywhere. Start with the topmost directory and iterate through all of its entries. Use the stat system call to distinguish regular files from directories. As you come across regular files and symbolic links, use the unlink system call to delete them. As you find subdirectories, keep recursing into them. Your recursion bottoms out at the point you reach a directory that only contains regular files and symbolic links but no more subdirectories. When you pop up from that directory, unlink it as well. This algorithm SHOULD work on any POSIX system, not just Mac OS X. While OS X uses the HFS+ filesystem, HFS+ can be accessed via POSIX filesystem calls. Extra credit if you preflight the entire process without deleting anything at all, just to check whether any unlinks would fail because you don't have permission. The permission bits are available in the structure returned from the stat system call. I'll send you my bill in the mail. Don Quixote -- Don Quixote de la Mancha quix...@dulcineatech.com http://www.dulcineatech.com Dulcinea Technologies Corporation: Software of Elegance and Beauty. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com