This is another installment in my series of articles about File-Find-Object. This time what I'll do is look at the APIs provided by other languages for recursively traversing directory trees to see if we can gain any future insights. Let's start with the prominent Perl APIs:
You probably all know File::Find, which is the built-in Perl 5 API for directory tree traversal. As I noted earlier in a previous post, it has several severe design limitations, including not having an iterative interface, and as a result not being capable of interrupted in the middle very easily, it cannot be instantiated and used to traverse an arbitrary number of directory trees in one process (due to its use of global variables) and only gives three variables - $File::Find::name, $File::Find::dir and $_ as arguments (whose meaning depend on the value of the no_chdir parameter).
This brings us to no_chdir which controls whether or not it changes to the directory containing the directory or file being reported. I can't think of any case where it would be desirable to cd to sub-directories or up, and in File-Find-Object Nanardon and I made a design decision of not changing directory ever.
The internals of File::Find are incredibly messy, hard to follow, and contain two nearly identical pieces of code that are chosen based on one of the flags. It also doen't use File::Spec, but instead relies on its own ad-hoc portable path mangling.
File-Next is Andy Lester's iterative directory traverser, that among other things is used in his ack grep-replacement tool. File::Next provides some iterative interfaces, but cannot be instantiated, and still uses several global variables, and uses several non-Object Oriented / non-exported functions. It also seems to provide some abstractions over the basic File::Find functionality which was implemented as a part of File-Find-Rule in File::Find's case, and later on File-Find-Object-Rule in File-Find-Object's case.
And naturally there's File-Find-Object, which is capable of instantiation, has an iterative interface and also returns result objects with some meta-data about the files and filenames.
Lately, I've become a little unhappy with the interface, as one can control the future traversal only of the deepest level, and not of an upper level in the tree. As a result, pruning several directories at once may require some relatively complex logic in higher-level code. I believe this can be remedied by providing some extra methods without breaking the external API.
Naturally, there are many abstractions on CPAN above these module like File-Find-Rule, or File-Find-Object-Rule, but they are out of scope of this post.
Now let's move on to the APIs provided by other languages and environments: