Java Directory FAQ: How do I walk a directory tree?

Java directory FAQ: How do I walk a directory tree and do something with the files and directories I find?

I've done this recently by extending the DirectoryWalker class of the Jakarta Commons IO project.

I was going to write an example here, but there are good examples in the DirectoryWalker API docs. The really short answer is (a) create your own class that extends the DirectoryWalker class, and (b) override the handleFile and handleDirectory methods of that class to do what you want with each file and directory.

The examples also show that you can do some really powerful things with standard FileFilters.