|
From: | Riccardo Mottola |
Subject: | Re: getting an absolute file path |
Date: | Thu, 19 Sep 2013 18:11:51 +0200 |
User-agent: | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0 SeaMonkey/2.21 |
Hi, Wolfgang Lux wrote:
Riccardo Mottola wrote:Hi, I am chasing a strange error in ProjectCenter that drives me crazy. Depending on how a project was opened, PC misbehaved. I tracked it down to certain paths depending on the project path being absolute vs. relative. Especially creations! What's the best way (= portable also to windows) to get the absolute path of a file or directory? I looked for methods in NSFileManager but found no easy route.In order to determine the absolute path you would need to know the base directory for the relative path. In case this is the directory of your project, you should query the NSDocument class or remember the path that was used to open the project. This is always an absolute path. You then can append the relative path to that directory using -stringByAppendingPathComponent:.
ProjectCenter triess to remember the path that was used to open the project.However from a bit of debugging, I found that if "ProjectCenter file.x" is invoked on the command line,
- (BOOL)application:(NSApplication *)application openFile:(NSString *)fileName
fileName results in just the file name, not the absolute path.When using "NSDocument" methods, that is open file, open recent and so on, I correctly always get a full path.
[[NSURL fileURLWithPath:fileName] path];Fixes my troubles, but I wonder then if I need to do that or not. If it is correct that application openFile doesn't get a "normalized" file path there.
Riccardo
[Prev in Thread] | Current Thread | [Next in Thread] |