iOS 创建文件夹,删除文件夹,对文件夹重命名的操作
2018-07-20 来源:open-open
+ (void)createFolder:(NSString *)folderName { NSString *imageDir = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(),folderName]; NSLog(@"HomeDir: %@",imageDir); 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]; } } + (void)deleteFolder:(NSString *)folderName { NSString *imageDir = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(),folderName]; NSLog(@"HomeDir: %@",imageDir); NSFileManager *fileManager = [NSFileManager defaultManager]; [fileManager removeItemAtPath:imageDir error:nil]; } + (void)changeFolderName:(NSString *)folderName beforeName:(NSString *)beforeName { NSFileManager *fm = [NSFileManager defaultManager]; NSString *beforeFolder = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(),beforeName]; NSString *afterFolder = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(),folderName]; [fm createDirectoryAtPath:afterFolder withIntermediateDirectories:YES attributes:nil error:nil]; NSDirectoryEnumerator *dirEnum = [fm enumeratorAtPath:beforeFolder]; NSString *path; while ((path = [dirEnum nextObject]) != nil) { [fm moveItemAtPath:[NSString stringWithFormat:@"%@/%@",beforeFolder,path] toPath:[NSString stringWithFormat:@"%@/%@",afterFolder,path] error:NULL]; } [fm removeItemAtPath:beforeFolder error:nil]; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:IOS截取屏幕到文件中
下一篇:IOS图形的裁剪
最新资讯
热门推荐