您的位置:首页 > 其它

NSFileManager的使用

2015-12-31 21:44 302 查看


#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
@autoreleasepool {

NSString * path = @"/Users/stone/Desktop/arr.plist";
// 1: 文件是否存在
NSFileManager * fm = [NSFileManager defaultManager];
BOOL isExist = [fm fileExistsAtPath:path];
if (isExist) {
NSLog(@"file exist");
}
else {
NSLog(@"not found file");
}

// 2: 判断是否是一个目录
NSString * path2 = @"Users/stone/Desktop";

BOOL isDir;
[fm fileExistsAtPath:path2 isDirectory:&isDir];
if (isDir) {
NSLog(@"is a directory");
}
else {
NSLog(@"is not a directory");
}

// 3: 判断文件是否可读

BOOL isReadable = [fm isReadableFileAtPath:path];
if (isReadable) {
NSLog(@"readable");
}
else {
NSLog(@"unreadable");
}

// 4: 是否可写
NSString * path3 = @"/";
BOOL isWritable = [fm isWritableFileAtPath:path3];
if (isWritable) {
NSLog(@"Writable");
}
else {
NSLog(@"unWritable");
}

// 5: 是否可删除
BOOL isDeletable = [fm isDeletableFileAtPath:path];
if (isDeletable) {
NSLog(@"deletable");
}
else {
NSLog(@"undeletable");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: