I’ve been watching this thread progress over time and it’s been very helpful and informative. I made an architectural design choice related to this topic that I would appreciate feedback on. I hope no one minds a topically-related aside here.
I have a FileSystem library (asobjc) that provides handlers for listing filesystem objects (list all contents, list top level contents, list folders, list files, list packages, list all Folders, Files, and Packages, list aliases, and list symlinks). These all return arrays of NSURLs.
I have an NSURL library (asobjc) that provides handers for filtering and sorting of arrays of NSURLs. I have 7 NSURL sorting handlers (access date, content mod date, attribute mod date, creation date, added date, name, size), and 24 NSURL filtering handlers (extension matches, filename matches, filename contains, path contains, access date before/after, mod date before/after, created date before/after, etc.). These all return arrays of NSURLs.
There are so many possible combinations of file/folder/package-property-matches-or-doesn’t-match-criteria that it’s impractical to try to write custom code for them all. But at some point I’m going to want all the files in a hierarchy whose name matches a search string, are the correct file type, and have been modified in the last 7 days, so I decided to separate the file-listing from the filtering and sorting.
NSURL array filtering
If you want to use multiple criteria to return filesystem objects the permutations can become enormous, so, instead of writing a ton of variations of ways to gather file/folder/packages matching or not matching some criteria, I decided to get the full set of NSURLs for the directory and then pass them through appropriate NSURL-filtering handlers. Since these filtering handlers also return an array of NSURLs you can pass them through as many filters as needed. You can combine any of these filtering handlers to achieve any subset of files you want without coding a specific combination.
Get some set of (file/folder/package NSURLs) and pass them through → (IS FILE filter) → (filename CONTAINS filter) → (extension MATCHES filter) → (created date AFTER filter) → (SORT by mod date)
Pertinent, I suppose, is that in addition to the file-folder-package listing handlers, I also have file-folder-package copy, duplicate, move, and delete handlers. Without making a number of variations on these file-manipulation handlers, I can use the NSURL filter handlers and get the functionality. i.e. When I want to Move all Folders in the targetDirectory whose name matches “temp” and whose created date is today I can just list the targetDirectory, filter for name is “temp”, filter for created date is today and pass the resulting list to the Move handler.
This made my libs more feature-complete, but also greatly reduced the amount of code I had in these libraries and it performs very well. Opinions, criticism or stark warnings of impending doom are welcome.