|
http://hi.baidu.com/lm382304817/blog/item/b12c70e26851103eb8382032.html
filePath:文件路径
NSDictionary *fileAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:filePath traverseLink:YES]; NSNumber *num = [fileAttributes objectForKey:NSFilePosixPermission]; NSLog(@"%04o", [num unsignedLongValue]); 这样就输出了该文件的权限,是用4位八进制数输出的,方便查看 给文件设置权限的话就是一个逆过程: filePath:文件路径 NSDictionary *theAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInteger:0555], NSFilePosixPermission,nil]; NSError *theError; [[NSFileManager defaultManager] setAttributes:theAttributes ofItemAtPath:filePath error:&theError]; 这样就给文件写了一个0555的权限,至于有没有写成功就看它的返回值了,错误信息在theError里。 |
Swift文件权限读写
本文介绍了如何使用Swift语言来读取和设置文件的权限。通过具体代码实例展示了如何利用NSFileManager来获取文件的Posix权限,并展示如何设置指定的权限。
9

被折叠的 条评论
为什么被折叠?



