New Methods for Directory Enumeration

In the last post by t524ube, I mentioned that I wanted some other methods in NSFileManager for enumerating folders, so I wrote a category on NSFileManager to create them. It seemed a little convoluted to me using the current methods, some give you full paths, others only the file or folder name, some do a shallow enumeration, others a deep one, and there was no easy way to get just folders or files without looping through the returned array. So I created a category with 3 methods in it, one to get files, one to get folders, and one that gets both. The methods are:


-(NSMutableArray *)foldersOfDirectoryAtLocation:(id) path isShallow:(BOOL) isShallow isFull:(BOOL) isFull;
-(NSMutableArray *)filesOfDirectoryAtLocation:(id) path isShallow:(BOOL) isShallow isFull:(BOOL) isFull;
-(NSMutableArray *)contentsOfDirectoryAtLocation:(id) path isShallow:(BOOL) isShallow isFull:(BOOL) isFull;

Each of these methods allows you to determine whether you want a deep or shallow enumeration, and whether the resulting array contains full paths (or URLs) or just the file or folder name. Additionally, you can pass either a POSIX path or a URL as the first argument. If you pass a POSIX path, the array returned will be POSIX paths, and if you pass a URL the array will contain URLs (unless you pass 0 for the isFull argument, in which case you get the last path component as an NSString).

I don’t know if there is a way to upload files to this forum for downloading, if not, anyone who wants this category can PM me, and I’ll send you the files. I can post the code here if anyone would like to see it – it’s in Objective-C of course, since sadly, categories aren’t available in ASOC.

Ric

Hi Ric,

Did you change you mail address? I didn’t receive your categories – if the offer is still applicable!

Thanks,

But for the benefit of lurkers, I’ll point out that ASObjC can still take full advantage of categories in their apps.