I am trying to write a general function to list directories.
I should like to specify the depth for the listing, the file types or extensions, only folders,only files or both , the type of files to exclude (packages, hidden files etc.), recursive or not.
i have so far used : subpathsOfDirectoryAtPath_error_ and array filtering, but this is not enough.
What is the best way to build such a method (taking performance into account) ?
What do you mean by “that is not enough”?
I don’t know that you have much choice – probably the better method is enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:, but that uses blocks and hence is out of bounds for ASObjC.
The other thing you might do is look around and see if someone has published an Objective-C class that does what you want.
Thanks for the fast answer.
By not enough I mean that i have to resolve all the issues because the result of the method is very extensive (this is mainly true for very deep folder structures) and that consumes much power.
I will try for the moment to see if I can fine tune the function until something else is available
If you want to control the depth, you might be best to do your own limited recursion. But apart from changing the depth, I’m not sure anything is going to be particularly fast. When you ask for only folders or whatever, something is still going to have to get all the information and filter it.