Directory enumeration gives wrong file type for aliases
Directory enumeration gives wrong file type for aliases
- Subject: Directory enumeration gives wrong file type for aliases
- From: Gabriel Zachmann <email@hidden>
- Date: Fri, 07 Oct 2016 16:21:55 +0100
I am trying to enumerate the contents of a directory (aka folder) using NSDirectoryEnumerator.
My problem is that the file attributes always returns NSFileTypeRegular,
no matter whether it is an alias/symlink or a regular file.
You can see my code below.
I have tried to retrieve the file attributes with attributesOfItemAtPath:error: , and with fileAttributes,
both dictionaries returned by those methods are exactly the same, AFAICS.
According to the documentation
https://developer.apple.com/reference/foundation/nsfilemanager/1410452-attributesofitematpath?language=objc
I would at least attributesOfItemAtPath:error expect to show NSFileTypeSymbolicLink for the aliases and symlinks.
Could some kind soul please shed some light on this? or give me a hint?
Thanks a lot in advance.
Best regards,
Gabriel.
My code:
- (void) scanDirectoryByHand: (NSString*) dir
{
NSDirectoryEnumerator * enumerator = [fmanager_ enumeratorAtPath: dir];
for ( NSString * file in enumerator )
{
fattrs = [fmanager_ attributesOfItemAtPath: [dir stringByAppendingPathComponent: file] error: NULL];
fattrs = [enumerator fileAttributes];
NSString * filetype = [fattrs objectForKey: NSFileType];
if ( ! [filetype isEqualToString: NSFileTypeRegular] ||
[NSNumber numberWithBool: YES] == [fattrs objectForKey: NSFileExtensionHidden] )
_______________________________________________
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