zoukankan      html  css  js  c++  java
  • 删除某个文件夹下的所有文件

        //删除本地文件夹下保存的文件
                        NSFileManager *fileManager = [NSFileManager defaultManager];
                        NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject];
                        NSString *dicrectoryPath = [docPath stringByAppendingPathComponent:@"Pic"];
                       
                        NSArray *fileList = [[NSArray alloc] init];
                        //fileList便是包含有该文件夹下所有文件的文件名及文件夹名的数组
                        fileList = [fileManager contentsOfDirectoryAtPath:dicrectoryPath error:nil];
                        for (NSString *path in fileList) {
                            if ([path containsString:@"png"]) {
                                NSString *filePath = [dicrectoryPath stringByAppendingPathComponent:path];
                                BOOL result1 = [fileManager removeItemAtPath:filePath error:nil];
                                if (result1) {
                                    NSLog(@"删除成功");
                                }
                            }
                        }
    //创建文件  将图片保存到该路径下
     
        NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
        NSTimeInterval a=[dat timeIntervalSince1970]*1000;
        NSString *timeString = [NSString stringWithFormat:@"%.0f", a];
       
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject];
        NSString *dicrectoryPath = [docPath stringByAppendingPathComponent:@"Pic"];
        NSString *filePath;
        BOOL rel = [fileManager fileExistsAtPath:dicrectoryPath isDirectory:nil];
        if (rel) {
            NSLog(@"存在文件夹");
           
            filePath = [dicrectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%@.png", [[DataHandle shareDataHandle] getLocalData:USERID], timeString]];
        } else {
            NSLog(@"不存在文件夹");
            NSError *error = nil;
            BOOL result = [fileManager createDirectoryAtPath:dicrectoryPath withIntermediateDirectories:YES attributes:nil error:&error];
            if (result) {
                filePath = [dicrectoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@%@.png", [[DataHandle shareDataHandle] getLocalData:USERID], timeString]];
            }
        }
        [data writeToFile:filePath atomically:YES];
  • 相关阅读:
    深度分析HTML5在移动开发方面的发展状况
    腾讯实习生笔试题
    更简洁的 CSS 清理浮动方式
    图片垂直居中的使用技巧
    Css Reset(复位)整理
    70565 Pro: Designing and Developing Enterprise Applications Using the Microsoft .NET Framework 3.5 考试感言
    Android SDK 有bug
    70540 TS: Microsoft Windows Mobile 5.0 Application Development 考试感言
    70565 Pro: Designing and Developing Enterprise Applications Using the Microsoft .NET Framework 3.5 考试感言
    TS:70503 Windows Communication Foundation TS: 70505 Windows Form Application Dev 考试感言
  • 原文地址:https://www.cnblogs.com/tian-sun/p/4849716.html
Copyright © 2011-2022 走看看