NSFileManager (BSAliasResolving)
Language: Objective-C, Author: Michele Balistreri
License: Public domain
A very simple category adding a method to resolve aliases from NSFileManager. The actual implementation is from some example on Apple documentation, slightly adapted. It works reliably for both aliases of files and folder.
NSFileManager (BSAliasResolving) source preview
// // NSFileManager+BSAliasResolving.m // Created by Michele Balistreri on 29/08/07. // #import "NSFileManager+BSAliasResolving.h" @implementation NSFileManager (BSAliasResolving) - (NSString *)resolveAliasForPath:(NSString *)aPath { NSString *resolvedPath = nil; CFURLRef url; url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)aPath, kCFURLPOSIXPathStyle, NO); if (url != NULL) { FSRef fsRef; if (CFURLGetFSRef(url, &fsRef)) { Boolean targetIsFolder, wasAliased; if (FSResolveAliasFile (&fsRef, true, &targetIsFolder, &wasAliased) == noErr && wasAliased) { CFURLRef resolvedUrl = CFURLCreateFromFSRef(NULL, &fsRef); if (resolvedUrl != NULL) { resolvedPath = (NSString *)CFURLCopyFileSystemPath(resolvedUrl, kCFURLPOSIXPathStyle); CFRelease(resolvedUrl); } } } CFRelease(url); } if (resolvedPath == nil) resolvedPath = [[NSString alloc] initWithString:aPath]; return [resolvedPath autorelease]; } @end
NSFileManager (BSAliasResolving) header preview
// // NSFileManager+BSAliasResolving.h // Created by Michele Balistreri on 29/08/07. // #import <Cocoa/Cocoa.h> @interface NSFileManager (BSAliasResolving) - (NSString *)resolveAliasForPath:(NSString *)aPath; /* If the path wasn't an alias the path itself will be returned */ @endDownload Archive
Compatible with:
- Mac OS X 10.1
- Mac OS X 10.2
- Mac OS X 10.3
- Mac OS X 10.4 PPC
- Mac OS X 10.4 Intel
- Mac OS X 10.5 PPC
- Mac OS X 10.5 Intel
Comments
Comment feed
