views:

190

answers:

1

This question tells how one can create directories in your resources path. Once created, how does one reference these directories?

I have created an html directory with a structure for my internal pages, now I want to load the index.html file from the html directory. Thus, I'll need the file path to it.

I can just use:

NSString *filename = [[NSBundle mainBundle] pathForResource:@"index" 
                                                     ofType:@"html"];

But what happens if there are two index.html files contained in the directory structure? Does it just find the first one? Can the referencing be more specific?

Little test project here that is not working if you want to take a look

+1  A: 

If you have a path that is copied into your resource bundle, you also should reference the path when looking for the resource like:

NSString *filename = [[NSBundle mainBundle] pathForResource:@"html/index" ofType:@"html"];

EDIT:

You cannot apparently just include the directory in the resource name (I believe you can for other similar calls like "imageNamed:" on UIImage). The working call is:

NSString *helpFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"html"];
Kendall Helmstetter Gelner
that returns a nil string...
Aran Mulholland
Then `index.html` isn't in the `html` folder.
MrMage
added a sample project to the question that the reference is failing in. i definitely have an index.html in the html directory. i must be doing something else a bit silly. have a look at the app delegate applicationDidFinishLaunching (where im doing the load)
Aran Mulholland
Using the sample project I figured out what was going on - see revised answer.
Kendall Helmstetter Gelner
thank you very much. answer and upvote. legend
Aran Mulholland