码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 创建文件夹,删除文件夹,对文件夹重命名的操作

时间:2015-05-31 00:07:59      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:ios

iOS 创建文件夹,删除文件夹,对文件夹重命名的操作

by 伍雪颖

+ (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];
}

iOS 创建文件夹,删除文件夹,对文件夹重命名的操作

标签:ios

原文地址:http://blog.csdn.net/rainlesvio/article/details/46279579

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!