@implementationnsstring (fileSize)-(unsignedLong Long) filesize{//Total sizeUnsignedLong LongSize =0; //File ManagerNsfilemanager *mgr =[Nsfilemanager Defaultmanager]; //file PropertiesNsdictionary *attrs =[Mgr Attributesofitematpath:self Error:nil]; if([Attrs.filetype isequaltostring:nsfiletypedirectory]) {//folder//get the size of the folder = = Gets the total size of all files in the folderNsdirectoryenumerator *enumerator =[Mgr Enumeratoratpath:self]; for(NSString *subpathinchenumerator) { //Full pathNSString *fullsubpath =[self stringbyappendingpathcomponent:subpath]; //Accumulate file size if([[Mgr Attributesofitematpath:fullsubpath error:nil].filetype isequaltostring:nsfiletypedirectory]) {// If you traverse to a folder, continue traversing, adding only the size of the file (not the folder)Continue; } size+=[Mgr Attributesofitematpath:fullsubpath error:nil].filesize; NSLog (@"---%@", Fullsubpath); } } Else{//fileSize =attrs.filesize; } returnsize;}@end
Calculate the classification of file sizes