iOS 创建文件夹,删除文件夹,对文件夹重命名的操作
iOS 创建文件夹,删除文件夹,对文件夹重命名的操作
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];
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。