discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question about path


From: Richard Frith-Macdonald
Subject: Re: Newbie question about path
Date: Thu, 17 Jul 2003 19:24:28 +0100


On Thursday, July 17, 2003, at 06:58 PM, Tima Vaisburd wrote:

Hello everybody,

What is the best way to convert relative path to absolute path?

I came up to

NSString * AbsolutePath(NSString * path)
{
    if ( ! [path isAbsolutePath] )
    {
        NSFileManager * fmgr = [NSFileManager defaultManager];
        NSString * dir = [fmgr currentDirectoryPath];
        NSArray * arr = [NSArray arrayWithObjects: dir, path, nil];
path = [[NSString pathWithComponents: arr] stringByStandardizingPath];
    }

    return path;
}

The shortest is probably ...

if ([path isAbsolutePath] == NO)
path = [[[NSFileManager defaultManager] currentDirectoryPath] stringByAppendingPathComponent: path];

You can standardize it too if that's important.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]