码迷,mamicode.com
首页 > 其他好文 > 详细

获取项目中代码行数、图片资源列表及大小

时间:2015-08-18 13:36:23      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

- (NSInteger)codeLinesWithPath:(NSString *)path{
    
    NSFileManager *fileManaget = [NSFileManager defaultManager];
    BOOL isDir = NO;
    BOOL isExist = [fileManaget fileExistsAtPath:path isDirectory:&isDir];
    
    if (!isExist) {
        return 0;
    }
    
    if (isDir) {//文件夹
        
        NSArray *arr = [fileManaget contentsOfDirectoryAtPath:path error:nil];
        
        int sum = 0;
        
        for (NSString *fileName in arr) {//文件(夹)
            
            NSString *fullPath = [NSString stringWithFormat:@"%@/%@",path,fileName];
            sum += [self codeLinesWithPath:fullPath];
            
        }
        
        return sum;
        
    }else{//文件
        
        /*
         NSString *extension = [[path pathExtension] lowercaseString];
         if (!([extension isEqualToString:@"h"] || [extension isEqualToString:@"m"] || [extension isEqualToString:@"mm"])) {
         return 0;
         }
         
         NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
         NSArray *arr = [content componentsSeparatedByString:@"\n"];
         
         return arr.count;
         */
        
        NSString *extension = [[path pathExtension] lowercaseString];
        if (!([extension isEqualToString:@"png"] || [extension isEqualToString:@"jpg"])) {
            return 0;
        }
        
        NSString *imageName = [path stringByReplacingOccurrencesOfString:@"/Users/xiaozeru/Desktop/HKProject/Res/" withString:@""];
        NSData *data = [NSData dataWithContentsOfFile:path];
        NSLog(@"imageName:%@--size:%dkb",imageName,data.length/1024);
        
        return 1;
        
    }
    
    return 0;
}

 

获取项目中代码行数、图片资源列表及大小

标签:

原文地址:http://www.cnblogs.com/xiangli/p/4739019.html

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