zoukankan      html  css  js  c++  java
  • iOS NSFileManager对沙盒文件及目录添加删除操作

    iOS 使用 NSFileManager对沙盒里面的文件和目录,增加,修改,删除操作;

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        self.title = @"NSFileManager";
        
        NSFileManager *defauleManager = [NSFileManager defaultManager];
        NSString *tempPath = NSTemporaryDirectory();
        NSLog(@"%@",tempPath);
        NSString *thePath = nil;
        
        //创建一个目录:  在temp下创建 MyFoler目录
    //    thePath = [NSString stringWithFormat:@"%@/MyFolder",tempPath];
    //    [defauleManager createDirectoryAtPath:thePath withIntermediateDirectories:YES attributes:nil error:nil];
        
        
        
        //写入一个文件  在 temp目录下
    //    NSString *aStr = @"hello world";
    //    thePath = [NSString stringWithFormat:@"%@hello.txt",tempPath];
    //    [aStr writeToFile:thePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
        
        
        //显示目录内容
        //NSLog(@"temp目录内容:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]);
        
        
        
        //删除一个文件
    //    NSString *deleteStr = @"delete Str";
    //    thePath = [NSString stringWithFormat:@"%@delete.txt",tempPath];
    //    [deleteStr writeToFile:thePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
    //    NSLog(@"temp目录内容:删除之前:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]);
    //    [defauleManager removeItemAtPath:thePath error:nil];
    //    NSLog(@"temp目录内容:删除之后:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]);
    
        
        
        //删除一个目录:
    //    thePath = [NSString stringWithFormat:@"%@/TestFoler",tempPath];
    //    [defauleManager createDirectoryAtPath:thePath withIntermediateDirectories:YES attributes:nil error:nil];
    //    NSLog(@"temp目录内容:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]);
    //    [defauleManager removeItemAtPath:thePath error:nil];
    //    NSLog(@"temp目录内容:%@",[defauleManager contentsOfDirectoryAtPath:tempPath error:nil]);
        
        
        //获取目录下的所有文件列表:
        NSArray *fileList = [defauleManager contentsOfDirectoryAtPath:tempPath error:nil];
        NSLog(@"%@",fileList);
        
        
        //判断一个目录是否是文件夹
        //- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory
    
        
        
        
        
        
    }
  • 相关阅读:
    POJ 3356 水LCS
    POJ 2250 (LCS,经典输出LCS序列 dfs)
    POJ 1080( LCS变形)
    整数划分问题之最大乘积
    进程调度之FCFS算法(先来先运行算法)
    c模拟银行家资源分配算法
    c模拟内存分配算法(首次适应算法,最佳适应算法,最坏适应算法)
    HDU 2602 Bone Collector(经典01背包问题)
    NYOJ 44 字串和 (最大字串和 线性dp)
    匈牙利游戏(codevs 1269)
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3479813.html
Copyright © 2011-2022 走看看