开发者

iPhone dev: Recurse all project resoureces and collect paths

开发者 https://www.devze.com 2022-12-28 22:17 出处:网络
I have a bunch of HTML resources in my app organized in a hierarchy like so: dirA |---> index.html |---> a1.html

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开发者_C百科 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消