How to resolve fileAttributesAtPath warning problems?

Now I use this code:

NSDictionary* attr = [[NSFileManager defaultManager] fileAttributesAtPath:file traverseLink:YES]; 

and get a warning:

 'fileAttributesAtPath:traverseLink:' is deprecated 

Who knows what to use instead?

Thanks!

+5
source share
5 answers

Use attributesOfItemAtPath:error: instead.

+8
source

use attributesOfItemAtPath:error:

 NSError* error; NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:file error:&error]; 
+4
source

The accepted answer forgot to process traverseLink:YES from the question.

The improved answer uses both attributesOfItemAtPath:error: and stringByResolvingSymlinksInPath :

 NSDictionary* attr = [[NSFileManager defaultManager] attributesOfItemAtPath:[file stringByResolvingSymlinksInPath] error:nil]; 
+1
source

Special considerations

Since this method does not return error information, it is deprecated like Mac OS X v10.5. Use setAttributes: ofItemAtPath: error: instead.

link

0
source

you should read the documentation :

fileAttributesAtPath: traverseLink:

Returns a dictionary that describes the attributes of the POSIX file specified in the specified. (Deprecated on Mac OS X v10.5. AttributesOfItemAtPath: error: instead.)

0
source

All Articles