Re: NSFileTypeAlias available?
Re: NSFileTypeAlias available?
- Subject: Re: NSFileTypeAlias available?
- From: Rainer Brockerhoff <email@hidden>
- Date: Thu, 27 Nov 2003 11:43:04 -0200
>
Date: Wed, 26 Nov 2003 22:45:35 +0100
>
From: Lorenzo <email@hidden>
>
>
Hi List,
>
I use to get the fileAttribute and understand whether a file is symLink with
>
>
fileType = [itemAttribute objectForKey:@"NSFileType"];
>
if(fileType == NSFileTypeSymbolicLink)
>
>
is a similar Cocoa way to know whether a file is an alias?
>
...
>
if the source file is really a symLink, FSPathMakeRef traverses the source
>
file and returns the FSRef of the target file and not the FSRef of the
>
source file itself. To workaround the problem
>
I have to build the FSRef using the parent folder of the source file
>
>
err = FSMakeFSRefUnicode(&sourceParentRef, sourceFileName.length,
>
sourceFileName.unicode, kTextEncodingFullName, sourceRef);
>
>
I know this could be even not a great problem, but please think in a loop of
>
100,000 files this is a waste of time.
>
Any faster solution?
I wrote:
>
The fastest and most reliable way, even for many thousands of items, is to use the BSD calls:
>
...
I shouldn't post to the list before having coffee ;-).
So here's the correct way:
#include <stat.h>
#include <files.h>
- (BOOL)pathIsAlias(NSString *)path {
struct stat info;
char* pathRep = [path fileSystemRepresentation];
if ((lstat(pathRep,&info)==0)&&!S_ISLNK(info.st_mode)) {
FSRef theRef;
if (FSPathMakeRef(pathRep,&theRef,NULL)==noErr) {
Boolean isAlias;
if ((FSIsAliasFile(&theRef,&isAlias,NULL)==noErr)&&isAlias) {
return YES;
}
}
}
return NO;
}
Calling FSPathMakeRef isn't all that slow for practical purposes, in my experience.
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"It's extremely unlucky to be superstitious, for no other reason
than it is always unlucky to be colossally stupid." (Stephen Fry)
Weblog:
http://www.brockerhoff.net/bb/viewtopic.php
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.