[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getting an absolute file path
From: |
Wolfgang Lux |
Subject: |
Re: getting an absolute file path |
Date: |
Thu, 19 Sep 2013 18:37:28 +0200 |
Riccardo Mottola wrote:
> 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.
Hmmm, I would have expected NSApplication to always pass an absolute path to
that method, but you can work around that by using some thing like
if (![fileName isAbsolutePath])
{
NSString *cwd = [[NSFileManager defaultManager] currentDirectoryPath];
fileName = [cwd stringByAppendingPathComponent: fileName];
}
in your delegate implementation.
Wolfgang