unexplained error with filemanager??

Discussion in 'Mac Programming' started by trey5498, Jul 22, 2008.

  1. trey5498 macrumors regular

    Joined:
    Jun 16, 2008
    #1
    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;
    	}
    	 
    }
    
     
  2. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    Are you expecting -currentDirectoryPath to return the path to your application? If so, use [[NSBundle mainBundle] bundlePath] instead.
     
  3. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #3

    -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.
     
  4. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #4
    There is no concept of a current working directory in Cocoa apps. Use -stringByRemovingLastPathComponent to remove the name from the bundle path.
     
  5. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #5
    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.
     
  6. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #6
    Xcode probably sets a working directory for some reason (logging maybe? dunno).
     
  7. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #7
    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?
     
  8. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #8
    What are the warnings? Also, I would recommend using stringByAppendingPathComponent rather than stringByAppendingString; it'll deal with things like accidentally doubling up on /s.
     

Share This Page