Re: URLByResolvingBookmarkData not case sensitive
Re: URLByResolvingBookmarkData not case sensitive
- Subject: Re: URLByResolvingBookmarkData not case sensitive
- From: "Stephen J. Butler" <email@hidden>
- Date: Tue, 06 Jan 2015 23:32:26 -0600
What about this (caveat: only works if the file exists):
@interface NSArray (FileNSURL)
- (NSUInteger) indexOfFileNSURL:(NSURL*)aFileURL error:(NSError**)error;
@end
@implementation NSArray (FileNSURL)
- (NSUInteger) indexOfFileNSURL:(NSURL *)aFileURL error:(NSError**)error {
id srcResourceID;
if (![aFileURL getResourceValue:&srcResourceID
forKey:NSURLFileResourceIdentifierKey error:error])
return NSNotFound;
// NSNotFound from now will not signal an error
if (error)
*error = nil;
return [self indexOfObjectPassingTest:^BOOL(id obj, NSUInteger
idx, BOOL *stop) {
id objResourceID;
// skip this obj if there is an error getting the ID key
if (![obj getResourceValue:&objResourceID
forKey:NSURLFileResourceIdentifierKey error:nil])
return NO;
else
return [objResourceID isEqual:srcResourceID];
}];
}
@end
On Tue, Jan 6, 2015 at 10:43 PM, Trygve Inda <email@hidden> wrote:
>> On Jan 6, 2015, at 7:40 PM, Kyle Sluder <email@hidden> wrote:
>>
>>> On Jan 6, 2015, at 5:05 PM, Trygve Inda <email@hidden> wrote:
>>>
>>>> If I bookmark a file and the case of any folders or the file itself changes,
>>>> then later when I extract the path from the bookmark I want it to reflect
>>>> the new case of the path as it now exists.
>>>
>>> Use -[NSFileManager componentsToDisplayForPath:]. Then you don’t even need to
>>> canonicalize anything yourself.
>>
>> Yes. Also, the components to display for a path are *not* the display name
>> for each path component. For example, the user never sees /Volumes.
>>
>> You should try to avoid displaying file paths to the user if at all possible.
>> If you must, try using an NSPathControl. That does additional simplification
>> of the path, like starting paths inside the user's home at the home folder and
>> not showing the parent directories of the home folder (e.g. /Users).
>>
>> If you really, really need to canonicalize a URL, you can try converting it to
>> a file reference URL using -fileReferenceURL and then back to a file path URL
>> using -filePathURL. See the documentation for -fileReferenceURL for caveats.
>> Also, this conversion can produce unexpected results in the face of symlinks
>> and/or hard links.
>
> Ultimately what I need to able to do is compare a bookmark to a path. I
> would like to do this using NSArray's indexOfObject with a path derived from
> the bookmark, but because the bookmark's path is not updated when only the
> case changes, this sort of comparison will not work.
>
> Basically I would like a method like:
>
> [bookmarkData isEqualToPath:path]
>
>
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden