获取目录详细信息的API是什么?

ite*_*nyh 1 iphone objective-c ipad

我是Objective-c的新手,我想获取本地目录的详细信息(如名称,大小,最后修改时间).有没有可以提供帮助的API?

Nav*_*eed 5

希望你能在这里找到答案:

可以使用attributesOfItemAtPath方法获取文件或目录的 属性.这将参数作为目录的路径和一个可选的NSError对象作为参数,其中将放置有关任何错误的信息(如果不需要此信息,则可以指定为NULL).结果以NSDictionary字典对象的形式返回(有关使用字典对象的详细信息,请参阅Objective-C字典对象).

这本词典的一些键:

NSFileType
NSFileTypeDirectory
NSFileTypeBlockSpecial
NSFileTypeUnknown
NSFileSize
NSFileModificationDate
NSFileOwnerAccountName
NSFileGroupOwnerAccountName
NSFilePosixPermissions
NSFileSystemNumber
NSFileCreationDate
NSFileOwnerAccountID
NSFileGroupOwnerAccountID
Run Code Online (Sandbox Code Playgroud)

以上文章的例子:

(我们可以使用以下代码摘录提取/ tmp目录的创建日期,文件类型和POSIX权限)

NSFileManager *filemgr;
NSDictionary *attribs;

filemgr = [NSFileManager defaultManager];

attribs = [filemgr attributesOfItemAtPath: @"/tmp" error: NULL];

NSLog (@"Created on %@", [attribs objectForKey: NSFileCreationDate]);
NSLog (@"File type %@", [attribs objectForKey: NSFileType]);
NSLog (@"POSIX Permissions %@", [attribs objectForKey: NSFilePosixPermissions]);
Run Code Online (Sandbox Code Playgroud)