计算ios沙盒中的文件大小

 [代码]计算缓存大小 沙盒下得文件    跳至 [1] [全屏预览]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-( float )fileSizeForDir:( NSString *)path //计算文件夹下文件的总大小
{
     
     NSFileManager *fileManager = [[ NSFileManager alloc] init];
     float size =0;
     NSArray * array = [fileManager contentsOfDirectoryAtPath:path error: nil ];
     for ( int i = 0; i<[array count]; i++)
     {
         NSString *fullPath = [path stringByAppendingPathComponent:[array objectAtIndex:i]];
         
         BOOL isDir;
         if ( !([fileManager fileExistsAtPath:fullPath isDirectory:&isDir] && isDir) )
         {
             NSDictionary *fileAttributeDic=[fileManager attributesOfItemAtPath:fullPath error: nil ];
             size+= fileAttributeDic.fileSize/ 1024.0/1024.0;
         }
         else
         {
             [ self fileSizeForDir:fullPath];
         }
     }
     han = han + size;
     return size;
}

你可能感兴趣的:(计算ios沙盒中的文件大小)