View the size of the picture resource in the project, whether to use

Source: Internet
Author: User

1. Global variables:

@property (nonatomic, assign) BOOL ispicused;

2. Method:

-(Nsinteger) Codelineswithpath: (NSString *) path{

Nsfilemanager *filemanaget = [Nsfilemanager Defaultmanager];

BOOL isdir = NO;

BOOL isexist = [Filemanaget fileexistsatpath:path isdirectory:&isdir];

if (!isexist) {

return 0;

}

if (isdir) {//Folder

Nsarray *arr = [Filemanaget contentsofdirectoryatpath:path error:nil];

int sum = 0;

For (NSString *filename in arr) {//file (clip)

NSString *fullpath = [NSString stringwithformat:@ "%@/%@", Path,filename];

Sum + = [self codelineswithpath:fullpath];

}

return sum;

}else{//file

/*

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"] | | [Extension isequaltostring:@ "GIF"]) {

NSString *imagename = path.lastpathcomponent;

Nsarray *imgarr = [ImageName componentsseparatedbystring:@ "@"];

ImageName = Imgarr.firstobject;

Imgarr = [ImageName componentsseparatedbystring:@ "];

ImageName = Imgarr.firstobject;

self.ispicused = NO;

[Self isimageusedwithimagename:[nsstring stringwithformat:@ "\"%@\ "", ImageName] path:@ "users/lixiang/desktop/ Crazyteacher/customer/crazyteacherapp "];

NSData *data = [NSData Datawithcontentsoffile:path];

NSLog (@ "lastpathcomponent:%@,imagename:%@,size:%.1fkb,isused:%d", [path stringbyreplacingoccurrencesofstring:@ ") Users/lixiang/desktop/crazyteacher/customer/crazyteacherapp "withstring:@" "],imagename,data.length/1024.0, self.ispicused);

return 1;

} else {

return 0;

}

}

return 0;

}

-(void) Isimageusedwithimagename: (NSString *) imageName path: (NSString *) path{

if (self.ispicused) {

Return

}

Nsfilemanager *filemanaget = [Nsfilemanager Defaultmanager];

BOOL isdir = NO;

BOOL isexist = [Filemanaget fileexistsatpath:path isdirectory:&isdir];

if (!isexist) {

}

if (isdir) {//Folder

Nsarray *arr = [Filemanaget contentsofdirectoryatpath:path error:nil];

For (NSString *filename in arr) {//file (clip)

NSString *fullpath = [NSString stringwithformat:@ "%@/%@", Path,filename];

[Self isimageusedwithimagename:imagename path:fullpath];

}

}else{//file

NSString *extension = [[path pathextension] lowercasestring];

if ([extension isequaltostring:@ "h"] | | [Extension isequaltostring:@ "M"] | | [Extension isequaltostring:@ "mm"] | | [Extension isequaltostring:@ "Xib"] | | [Extension isequaltostring:@ "StoryBoard"]) {

NSString *content = [NSString stringwithcontentsoffile:path encoding:nsutf8stringencoding Error:nil];

if ([content Containsstring:imagename]) {

self.ispicused = YES;

}

}

}

}

3. Call

Nsinteger linecount = [self codelineswithpath:@ "Users/lixiang/desktop/crazyteacher/customer/crazyteacherapp"];

View the size of the picture resource in the project, whether to use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.