Re: Irritating Problem with NSString Method and File Paths
Re: Irritating Problem with NSString Method and File Paths
- Subject: Re: Irritating Problem with NSString Method and File Paths
- From: Negm-Awad Amin <email@hidden>
- Date: Tue, 5 Aug 2008 10:01:10 +0200
The file is inside your application directory? Than you should use
NSBundles's API to find resources.
NSString* thePath = [[NSBundle mainBundle] pathForResource:filename
ofType:@"txt"]
Amin
Am Mo,04.08.2008 um 06:43 schrieb Patrick Walker:
It seems that whenever I use Xcode to spawn the program, it is able
to find the file but when spawning the program from Finder, it can
never, ever find the file. I've been looking online and no one
seems to have come across this before or maybe it's because it's so
late that I'm not seeing the obvious.
NSString *fileContents = [[NSString alloc] initWithContentsOfFile:
[filename stringValue]
encoding:NSASCIIStringEncoding
error:nil];
Filename is an NSTextField outlet, btw.
We've tried all sorts of things to try and find the file,
File.txt, ./File.txt, ~/File.txt, "./File.txt". I can understand
maybe the ~ doesn't work for all shells but explicitly using
./File.txt should be opening the file in the current directory with
the executable, shouldn't it? Do I *really* have to append a huge
long path each time I want to open a file?
Any ideas? It says path and the documentation says that it has to
be NSString. I've used filepaths before for open() but those are C
strings and those are full paths though, i.e., /dev/stdout. It's
such a simple problem what am I missing here?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
Amin Negm-Awad
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden