A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

<div><span style="font-weight: bold;"><font size="5" face="微软雅黑">
</font></span></div><div style="text-align: left;"><p>  <font size="3">+ (void)createFolder:(NSString *)folderName {</font></p>
<p><font size="3">  NSString *imageDir = [NSString stringWithFormat:@"%@/Documents/%@",
NSHomeDirectory(),folderName];</font></p>
<p><font size="3">  NSLog(@"HomeDir: %@",imageDir);</font></p>
<p><font size="3">  BOOL isDir = NO;</font></p>
<p><font size="3">  NSFileManager *fileManager = [NSFileManager defaultManager];</font></p>
<p><font size="3">  BOOL existed = [fileManager fileExistsAtPath:imageDir
isDirectory:&isDir];</font></p>
<p><font size="3">  if ( !(isDir == YES && existed == YES) )</font></p>
<p><font size="3">  {</font></p></div>
<div style="text-align: center;">
</div><div>
<p><font size="3">  [fileManager createDirectoryAtPath:imageDir withIntermediateDirectories:YES
attributes:nil error:nil];</font></p>
<p><font size="3">  }</font></p>
<p><font size="3">  }</font></p></div>

<p><font size="3">  NSString *imageDir = [NSString stringWithFormat:@"%@/Documents/%@",
NSHomeDirectory(),folderName];</font></p>
<p><font size="3">  NSLog(@"HomeDir: %@",imageDir);</font></p>
<p><font size="3">  NSFileManager *fileManager = [NSFileManager defaultManager];</font></p>
<p><font size="3">  [fileManager removeItemAtPath:imageDir error:nil];</font></p>
<p><font size="3">  }</font></p>

<p><font size="3">  NSString *imageDir = [NSString stringWithFormat:@"%@/Documents/%@",
NSHomeDirectory(),folderName];</font></p>
<p><font size="3">  NSLog(@"HomeDir: %@",imageDir);</font></p>
<p><font size="3">  NSFileManager *fileManager = [NSFileManager defaultManager];</font></p>
<p><font size="3">  [fileManager removeItemAtPath:imageDir error:nil];</font></p>
<p><font size="3">  }</font></p>


<p><font size="3">  + (void)changeFolderName:(NSString *)folderName beforeName:(NSString
*)beforeName {</font></p>
<p><font size="3">  NSFileManager *fm = [NSFileManager defaultManager];</font></p>
<p><font size="3">  NSString *beforeFolder = [NSString stringWithFormat:@"%@/Documents/%@",
NSHomeDirectory(),beforeName];</font></p>
<p><font size="3">  NSString *afterFolder = [NSString stringWithFormat:@"%@/Documents/%@",
NSHomeDirectory(),folderName];</font></p>
<p><font size="3">  [fm createDirectoryAtPath:afterFolder withIntermediateDirectories:YES
attributes:nil error:nil];</font></p>
<p><font size="3">  NSDirectoryEnumerator *dirEnum = [fm enumeratorAtPath:beforeFolder];</font></p>
<p><font size="3">  NSString *path;</font></p>
<p><font size="3">  while ((path = [dirEnum nextObject]) != nil) {</font></p>
<p><font size="3">  [fm moveItemAtPath:[NSString
stringWithFormat:@"%@/%@",beforeFolder,path]</font></p>
<p><font size="3">  toPath:[NSString stringWithFormat:@"%@/%@",afterFolder,path]</font></p>
<p><font size="3">  error:NULL];</font></p>
<p><font size="3">  }</font></p>

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马