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;
}
相关文章推荐
- BZOJ 4104 [Thu Summer Camp 2015]解密运算
- MarkDown基本语法
- [DataStructure]多项式加法与乘法--B.链表存储(适用于零元系数多的多项式)
- web.xml中Filter,Listener,Servlet的区别
- Nginx 设置临时维护页面
- 仿按键抓抓
- 15再见,16你好。
- GTK编程
- 湖南集训Day6
- socket之回射c/s模型(一)
- 客户端访问https站点(自定义证书)
- mental ray渲染引擎----环境映射
- AndroidStudio 1.4配置NDK
- 数据结构(四)
- MS chart 非常详细的例子,实现拖动放大
- 关于美国最高法院的几个网站(持续补充)
- 状态栏高度和标题栏高度
- 生产实习(Android)八
- django乱码问题
- 2015年总结