views:

34

answers:

1

I have a bunch of HTML resources in my app organized in a hierarchy like so:

dirA
|---> index.html
|---> a1.html
|---> a2.html
|---> dirB
      |---> b1.html
      |---> b2.html
|---> dirC
      |---> c5.html
      |---> c19.html

I'm trying to collect the absolute paths of all HTML resources however deep down, but can't seem to figure out how. So far I've tried:

NSArray myPaths = [[NSBundle mainBundle] pathsForResourcesOfType:@"html" inDirectory:nil];

This returns an empty array, because I have no HTML files at the root of my project. Then there is:

NSArray myPaths = [[NSBundle mainBundle] pathsForResourcesOfType:@"html" inDirectory:@"dirA"];

This returns an array containing only the paths for the three HTML resources directly below dirA. If I read the doc correctly, I guess this is to be expected; pathsForResourcesOfType does not traverse subdirectories. But is there a (preferably nice) way to do it?

+2  A: 

You can use an NSDirectoryEnumerator to iterate everything, then just check if the string's pathExtension is "html". If it is, you've found one.

Dave DeLong
Thanks! I ended up using [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:path error:
thomax