Searching Within .app For Files
Currently I'm loading my images with the standard code:
This works fantastically if File.png is right in the resources folder in my .app package. What if I add a bunch of folders in there by dragging a big folder tree into my app and setting it to create references for each folder? How can I get the program to find File.png without having to use something like
I tried just leaving it but I don't get anything. Basically I don't want to have to worry about what folder an image is in. I just want my app to find it and load it. Any advice? This would help greatly.
Code:
NSImage myImage = [NSImage imageNamed:@"File.png"];Code:
NSImage myImage = [NSImage imageNamed:@"Folder1/Folder2/Folder3/Folder4/File.png"];PHP Code:
system("find app.app | grep filename");
It's not magic, it's Ruby.
Nayr Wrote:PHP Code:
system("find app.app | grep filename");
Nayr: Try running that code and see what it actually does.

Nick: The feature you're looking for doesn't really exist. As far as Cocoa knows, you could have a file with the same name in every one of your subdirectories. You're going to have to specify which subdirectory the file is in. It doesn't have to be part of the filename; take a look at NSBundle's -pathForResource:ofType:inDirectory:.
Having a nice, well-organized directory structure in your Resources folder isn't really necessary, as it's not visible to the user unless they go poking inside your bundle. I'd suggest just sticking it all in one directory, or a few subdirectories if it makes sense.
- Alex Diener
Nick Wrote:Basically I don't want to have to worry about what folder an image is in. I just want my app to find it and load it.
...And I thought users would be the ones getting spoiled by Spotlight, I guess I was wrong!
I haven't tried this code but I think it should work for what you're trying to do Nick. Like ThemsAllTook said, there isn't anything currently available that will do exactly what you're asking for. You'll have to specify the directory.
Code:
NSString *path;
NSImage *myImage;
path = [[NSBundle mainBundle] bundlePath];
path = [path stringByAppendingPathComponent:@"Contents/Resources/Folder1"];
myImage = [[NSImage alloc] initWithContentsOfFile:[path stringByAppendingPathComponent:@"File.png"]];
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Searching for vertexes... | mikey | 20 | 6,473 |
Nov 10, 2009 10:37 AM Last Post: mikey |
|
| Searching Headers & Documentation | OneSadCookie | 0 | 1,935 |
May 1, 2006 11:31 PM Last Post: OneSadCookie |
|

