Re: NSFileManager -componentsToDisplayForPath:path
Re: NSFileManager -componentsToDisplayForPath:path
- Subject: Re: NSFileManager -componentsToDisplayForPath:path
- From: Ryan Britton <email@hidden>
- Date: Wed, 23 Nov 2005 21:43:23 -0800
As a follow-up, LSCopyDisplayNameForRef() appears to behave as
expected, so I'm going with that instead. Radar #4353940 filed for
the original.
The first is the old code, second is new:
2005-11-22 10:37:24.585 Test Bed[2529] Macintosh HD/......../Versions/
A/Resources
2005-11-22 10:37:24.586 Test Bed[2529] Macintosh HD/......../Resources
For anyone curious, here's my work-around:
- (NSString *)displayPathForPath:(NSString *)path
{
NSString *pathComponent;
NSEnumerator *e;
NSString *currentPath = @"";
NSString *displayPath = @"";
e = [[path pathComponents] objectEnumerator];
while (pathComponent = [e nextObject])
{
FSRef ref;
OSStatus result;
currentPath = [currentPath
stringByAppendingPathComponent:pathComponent];
result = FSPathMakeRef((UInt8 *) [currentPath UTF8String], &ref,
NULL);
if (result == noErr)
{
CFStringRef displayComponent;
LSCopyDisplayNameForRef(&ref, &displayComponent);
[(NSString *) displayComponent autorelease];
displayPath = [displayPath stringByAppendingPathComponent:
(NSString *) displayComponent];
}
else
{
return path;
}
}
return displayPath;
}
On Nov 22, 2005, at 10:08 AM, Ryan Britton wrote:
I have the following in an NSFileManager category. Problem is,
componentsToDisplayForPath: resolves aliases. Is this by design or
is it a bug? I'm inclined to think it's a bug. If so, has anyone
run into this before and come up with a work-around for it? I can
process the path differently and check to see if each component is
a alias, but I'd prefer not to have that additional overhead if
there's a better way.
- (NSString *)displayPathForPath:(NSString *)path
{
NSEnumerator *e;
NSArray *components;
NSString *displayPath = @"";
NSString *pathComponent;
components = [self componentsToDisplayForPath:path];
if (!components) //Unable to localize path, return the raw string
{
return path;
}
e = [[self componentsToDisplayForPath:path] objectEnumerator];
while (pathComponent = [e nextObject])
{
displayPath = [displayPath
stringByAppendingPathComponent:pathComponent];
}
return displayPath;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden