nsfilemanger 怎么求沙盒目录下某一文件夹的大小
2013-03-20 13:07
239 查看
+(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];
}
}
[fileManager release];
return size;
}
转自
http://www.cocoachina.com/ask/questions/show/94167/nsfilemanger%E6%80%8E%E4%B9%88%E6%B1%82%E6%B2%99%E7%9B%92%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%9F%90%E4%B8%80%E6%96%87%E4%BB%B6%E5%A4%B9%E7%9A%84%E5%A4%A7%E5%B0%8F
{
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];
}
}
[fileManager release];
return size;
}
转自
http://www.cocoachina.com/ask/questions/show/94167/nsfilemanger%E6%80%8E%E4%B9%88%E6%B1%82%E6%B2%99%E7%9B%92%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%9F%90%E4%B8%80%E6%96%87%E4%BB%B6%E5%A4%B9%E7%9A%84%E5%A4%A7%E5%B0%8F
相关文章推荐
- iOS 计算沙盒目录下一个文件夹的总大小
- java 取得文件、文件夹/ 目录 的 大小
- 查看Linux文件目录的大小和文件夹包含的文件数
- linux 系统统计目录下文件夹的大小
- C语言实现查看一个文件夹目录里面所有内容的大小功能
- SHELL编程练习-获得指定目录下的所有文件及文件夹的大小
- spquery查询某一目录下所有文档和文件夹
- [转]Asp.Net 文件操作基类(读取,删除,批量拷贝,删除,写入,获取文件夹大小,文件属性,遍历目录)
- TreeSize Free-查看每个文件夹的大小(目录树方式)
- Asp.Net 文件操作基类(读取,删除,批量拷贝,删除,写入,获取文件夹大小,文件属性,遍历目录)(一)
- du -sh*查看当前目录下的文件夹大小
- linux/aix怎么用命令查看某个目录下子目录占用空间的大小?
- JS 实现遍历某一磁盘文件夹下目录的功能
- 查看ubuntu文件目录的大小和文件夹包含的文件数 zT
- C++遍历文件夹及判断某一文件或目录是否存在
- 在asp.net(C#)中怎么获得一个目录的大小?
- freebsd中查看文件夹/目录大小的方法/命令
- 计算沙盒中Libray/Caches目录里所有文件的大小
- Asp.Net 文件操作基类(读取,删除,批量拷贝,删除,写入,获取文件夹大小,文件属性,遍历目录)(二)
- linux 查看各目录(文件夹)下文件大小