美文网首页
XCode批量移动文件夹的图片

XCode批量移动文件夹的图片

作者: 面糊 | 来源:发表于2017-12-21 17:43 被阅读80次
  • 要从项目中的Assets中将所有图片一个个拿出来比较麻烦, 使用Command Line Tool轻松把文件夹中所有的图片摘出来

      #import <Foundation/Foundation.h>
      
      int main(int argc, const char * argv[]) {
          @autoreleasepool {
              
              NSString *fromPath = @"/Users/fanghe/Desktop/iOS/Test/Test/Assets.xcassets/Tag/";
              NSString *toPath = @"/Users/fanghe/Desktop/iOS/MyDirectory/Tag/";
              NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:fromPath];
              
              NSString *file;
              while ((file = [dirEnum nextObject])) {
                  if ([[file pathExtension] isEqualToString: @"png"]) {
                      // 拼接路径
                      NSString *imagePath = [NSString stringWithFormat:@"%@%@", fromPath, file];
                      NSString *filePath = [file substringFromIndex:[file rangeOfString:@"/"].location + 1];
                      NSString *imageToPath = [NSString stringWithFormat:@"%@%@", toPath, filePath];
                      NSError *error = nil;
                      [[NSFileManager defaultManager] moveItemAtPath:imagePath toPath:imageToPath error:&error];
                  }
              }
          }
          return 0;
      }

相关文章

网友评论

      本文标题:XCode批量移动文件夹的图片

      本文链接:https://www.haomeiwen.com/subject/ylnawxtx.html