ios 下创建,删除文件夹的方法

创建文件夹:

NSString *imageDir = [NSString stringWithFormat:@"%@/Caches/%@", NSHomeDirectory(), dirName];


BOOL isDir = NO;


NSFileManager *fileManager = [NSFileManager defaultManager];


BOOL existed = [fileManager fileExistsAtPath:imageDir isDirectory:&isDir];


if ( !(isDir == YES && existed == YES) )


{


  [fileManager
createDirectoryAtPath:imageDir
withIntermediateDirectories:YES
attributes:nil error:nil];


}






删除文件夹及文件级内的文件:


NSString *imageDir = [NSString stringWithFormat:@"%@/Caches/%@", NSHomeDirectory(), dirName];


NSFileManager *fileManager = [NSFileManager defaultManager];


[fileManager
removeItemAtPath:imageDir error:nil];

你可能感兴趣的:(ios 下创建,删除文件夹的方法)