List Files In A Directory And All Subdirectores

Following is a few lines of Objective-C code to quickly traverse a directory and all of its subdirectories.

Let’s start with a file structure in the Documents directory that I used for my example:

The example I am writing is using the simulator, thus the folder structure shown above is from my Mac. However, the same applies regardless of the platform.

Line 17 is the most relevant line of code, wherein the enumerator manages traversing the current directory and all subdirectories. From there I check whether or not the object returned is a file or directory and output the results.