IOS中级篇 —— NSFileManager常用方法

[fileManager isDeletableFileAtPath:<#(NSString *)#>]; 判断一个路径是否可删除

[fileManager isWritableFileAtPath:<#(NSString *)#>];??判断一个路径是否可写

[fileManager isReadableFileAtPath:<#(NSString *)#>];??判断一个路径是否可读

[fileManager fileExistsAtPath:<#(NSString *)#>];????判断一个路径是否存在

?

[fileManager fileExistsAtPath:<#(NSString *)#> isDirectory:<#(BOOL *)#>]; 判断一个路径是否是一个文件夹?? bool需要传进??返回的值存在bool中

?

[fileManager attributesOfItemAtPath:<#(NSString *)#> error:<#(NSError *__autoreleasing *)#>];??显示详细信息

????

?获取文件夹下的所以文件?? 递归

[fileManager subpathsAtPath:path];

?

[fileManager subpathsOfDirectoryAtPath:path error:&error];

?

- (NSArray *)subpathsOfDirectoryAtPath:(NSString *)path error:(NSError **)error;?? 非递归

?

?

获取文件夹下的文件夹

[fileManger contentsOfDirectoryAtPath:path error:&err (error:nil)]

?

创建文件夹

[fileManager createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:nil];

?

创建文件 事先需要一个NSData

NSData?*data = [str?dataUsingEncoding:NSUTF8StringEncoding];

[fileManager?createFileAtPath:[NSString?stringWithFormat:@"%@/1.txt",path]?contents:data?attributes:nil];

?

文件拷贝??文件夹不存在刚会失败 不会新建文件夹

[fileManager copyItemAtPath:[NSString stringWithFormat:@"%@/1.txt",path] toPath:[NSString stringWithFormat:@"%@/bbb/1.txt",path] error:nil];

文件移动??文件夹不存在刚会失败 不会新建文件夹

[fileManager?moveItemAtPath:[NSString?stringWithFormat:@"%@/1.txt",path]?toPath:[NSString?stringWithFormat:@"%@/ddd/1.txt",path]?error:nil];

文件移除

[fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/1.txt",path] error:nil];

时间: 2024-08-30 06:59:02

IOS中级篇 —— NSFileManager常用方法的相关文章

IOS——中级篇 --TableView以及Cell

????? //? 设置tableView的行高 ??? self.tableView.rowHeight = 100;//? 设置tableView分割线的样式//? UITableViewCellSeparatorStyleNone 不显示分割线//? UITableViewCellSeparatorStyleSingleLine? 显示分割线(默认) ??? self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingl

IOS中级篇—— 多线程--NSOperation

NSOperation 操作? 任务是对代码的封装, 操作是对任务的封装 --目的:就是可以随时的暂停/恢复/取消任务; NSOperation 对GCD的封装. OC 运用起来更加方便. 抽象类. 车 NSOperation的使用: <1> 操作直接调用 start方法,就是在当前线程执行(Block中封装的任务数大于1的情况除外). <2> 就是将操作放在队列中.自动的帮我们开启线程,来执行操作. 两个子类: NSInvocationOperation: 调用 ? ? ? 1.

IOS中级篇 —— 多线程 - GCD

GCD 是c语言的框架,不需要手动管理内存 是一个面向任务   不是面向线程,不需要管理线程的生命周期 GCD 任务/队列 执行函数 任务:Block  任务都封闭在Block中.  —— 线程执行 队列:存放任务    FIFO (先进先出的原则) GCD中的队列: 串行队列:想要任务按顺序执行 //    创建一个串行队列 dispatch_queue_t serialQueue = dispatch_queue_create("serial", DISPATCH_QUEUE_SE

IOS中级篇 —— 日期时间对象

结合NSCalendar和NSDate能做更多的日期\时间处理 获得NSCalendar对象 NSCalendar *calendar = [NSCalendar currentCalendar];?获得年月日 - (NSDateComponents *)components:(NSCalendarUnit)unitFlags fromDate:(NSDate *)date; //创建日期 NSDate?*d = [NSDate?date]; //创建日期对象 NSCalendar?*ca =

IOS中级篇——何时使用copy,strong,weak,assign关键字 定义属性

? 父类指针可以指向子类对象 ? //定义block别名. typedef void (^LYItemOption)(); @interface LYItemArrow : LYItem@property(nonatomic,strong) Class desController; @property(nonatomic,copy) LYItemOption option; ? ? 1.strong :除NSString\block以外的OC对象 ? @property(nonatomic,st

IOS中级篇 —— Autoresizing

? UIView *blueView = [[UIView alloc] init]; ??? [self.view addSubview:blueView]; ??? blueView.backgroundColor = [UIColor blueColor]; ??? ??? blueView.center = self.view.center; ??? blueView.bounds = CGRectMake(0, 0, 150, 150); ??? self.blueView = blu

IOS中级篇 —— 关于深复制和浅复制

?深复制(深拷贝,内容拷贝,deep?copy) ?源对象和副本对象是不同的两个对象 ?源对象引用计数器不变,?副本对象计数器为1(因为是新产生的) ?本质是:产生了新的对象 ? ?浅复制(浅拷贝,指针拷贝,shallow?copy) ?源对象和副本对象是同一个对象 ?源对象(副本对象)引用计数器?+?1,?相当于做一次retain操作 ?本质是:没有产生新的对象

IOS中级篇 —— 手动内存管理

retainCount?? //dealloc方法,是对象的临终遗言的方法 //对象被销毁的时候,会默认的调用该方法 //注意:dealloc 方法是系统根据引用计数器的值,自动调用的, 野指针 内存泄露 @property??参数 @class 使用 循环retain解决方法 自动释放池?? @autoreleasepool

IOS中级篇 —— 字典转模型

@property (nonatomic, copy) NSString *icon;@property (nonatomic, copy) NSString *name; -(instancetype) initWithDic:(NSDictionary *)dic; +(instancetype) appViewWithDic:(NSDictionary *)dic; -(instancetype)initWithDic:(NSDictionary *)dic{ ?? if ([super