linyawen

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

转自  http://blog.csdn.net/txinfo/article/details/7347515

要做一个本地文件管理的小功能,获取应用沙盒目录及文件列表的方法都比较常见,但是想获取指定文件大小时,网上却很少提及,看了半天源码,才找到地方,在这里share一下:

 

 

NSFileManager *fm  = [NSFileManager defaultManager];

 

// 取文件大小

NSError *error = nil;

NSDictionary* dictFile = [[fm attributesOfItemAtPath:fullFile error:&error] retain];

if (error)

{

NSLog(@"getfilesize error: %@", error);

return NO;

}

long nFileSize = [dictFile fileSize]; //得到文件大小

[dictFile release];

 

NSDictionary声明里,还可以找得到文件修改时间,文件类型等信息

 

 

@interface NSDictionary (NSFileAttributes)

- (unsigned long long)fileSize;

- (NSDate *)fileModificationDate;

- (NSString *)fileType;

posted on 2012-08-19 15:03  linyawen  阅读(4419)  评论(0编辑  收藏  举报