删除指定路径下的所有文件

2018-02-07  本文已影响5人  番薯大佬
+ (void)deleteFiles:(NSString *)path
{
        NSFileManager *fileManger = [NSFileManager defaultManager];
        BOOL isDir = NO;
        BOOL isExist = [fileManger fileExistsAtPath:path
isDirectory:&isDir];
        if (isExist) 
        {
                if (isDir) 
                {
                        NSArray *dirArray = [fileManger
contentsOfDirectoryAtPath:path error:nil];
                        NSString *subPath = nil;
                        for (NSString * str in dirArray) 
                        {
                                subPath  = [path
stringByAppendingPathComponent:str];
                                BOOL issubDir = NO;
                                [fileManger fileExistsAtPath:subPath
isDirectory:&issubDir];
                                [self deleteFiles:subPath];
                        }
                }
                else
                {
                        NSLog(@"%@",path);
                        [manager removeItemAtPath:filePath error:nil];
                } 
        }
        else
        {
                NSLog(@"            ");
        }
}
上一篇下一篇

猜你喜欢

热点阅读