Typically used to delete a cache, calculate the cache size//size of a single file-(Long Long) Filesizeatpath: (nsstring*) filepath{ nsfilemanager* manager = [ Nsfilemanager Defaultmanager]; if ([manager Fileexistsatpath:filepath]) { return [[Manager Attributesofitematpath:filepath Error:nil] fileSize]; } return 0;} Traverse folder to get the folder size, return how many m (float) Foldersizeatpath: (nsstring*) folderpath{ nsfilemanager* manager = [Nsfilemanager Defaultmanager]; if (![ Manager Fileexistsatpath:folderpath]) return 0; Nsenumerator *childfilesenumerator = [[manager Subpathsatpath:folderpath] objectenumerator]; nsstring* FileName; Long long foldersize = 0; while ((FileName = [Childfilesenumerator nextobject]) = nil) { nsstring* fileabsolutepath = [FolderPath Stringbyappendingpathcomponent:filename]; Foldersize + = [self Filesizeatpath:fileabsolutepath]; } Return foldersize/(1024.0*1024.0);}
Calculate the file size in a folder in iOS