Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

trey5498

macrumors regular
Original poster
The following code works in the debugger and running it out of Xcode. tmpsourcec gets an actual path. However the moment i build it for release the path becomes //10.5/... instead of the path it gets out of xcode. Am I forgetting to include anything?



Code:
- (NSString *)Color: (NSString *)ColDvr
{
	tmpsourcec = [[fileManager currentDirectoryPath] stringByAppendingString:@"/10.5/Xerox Phaser 7760GX.gz"];
	NSRunAlertPanel(@"Directory Path", (@"The path is %s",tmpsourcec), @"Ok", nil, nil);
	dvrchk = [fileManager fileExistsAtPath:sourcecolor];
	if (dvrchk == NO)
	{
		[fileManager copyPath:[[fileManager currentDirectoryPath] stringByAppendingString:@"/10.5/Xerox Phaser 7760GX.gz"] toPath:@"/Library/Printers/PPDs/Contents/Resources/Xerox Phaser 7760GX.gz" handler:nil];
	}
	dvrchk = [fileManager fileExistsAtPath:sourcecolor];
	if (dvrchk == NO)
	{
		ColDvr = @"no";
		return ColDvr;
	} else {
		ColDvr = @"yes";
		return ColDvr;
	}
	 
}
 
Are you expecting -currentDirectoryPath to return the path to your application? If so, use [[NSBundle mainBundle] bundlePath] instead.
 
Are you expecting -currentDirectoryPath to return the path to your application? If so, use [[NSBundle mainBundle] bundlePath] instead.


-currentDirectoryPath returns the path correctly when it is in xcode/debugging environment. The error comes out of it. and when I tried [[NSBundle mainBundle] bundlePath] it give me the application name as well, I just need the current working directory.
 
There is no concept of a current working directory in Cocoa apps. Use -stringByRemovingLastPathComponent to remove the name from the bundle path.
 
Code:
NSString *tmpsourcec = [[[NSBundle mainBundle] bundlePath] stringByRemovingLastPathComponent stringByAppendingString:@"/10.5/Xerox Phaser 7760GX.gz"];

that will work? And how come my code works and gives the right current directory in the debugging environment and not in release, doesn't make sense.
 
Code:
NSString *tmpsourcec = [[[[NSBundle mainBundle] bundlePath] stringByRemovingLastPathComponent] stringByAppendingString:@"/10.5/Xerox Phaser 7760GX.gz"];

this keeps giving me warnings and obviously doesnt work. Where did I mess up?
 
What are the warnings? Also, I would recommend using stringByAppendingPathComponent rather than stringByAppendingString; it'll deal with things like accidentally doubling up on /s.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.