获取文件属性

获取文件属性

问题描述:

如何使用xcode获取pdf,gif,doc等文件的大小。 假设我得到PDF文件形式resorce文件夹,所以我怎么能得到这个文件的大小。获取文件属性

有什么办法吗?

谢谢你,

如果要计算你的资源文件在运行时的大小基本上你可以做以下(省略错误检查等):

// Get path for resource file 
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"myPDFFile" ofType:@"pdf"]; 
// Get file attributes 
NSDictionary* attributeDict = [[NSFileManager defaultManager] attributesOfItemAtPath:resourcePath error:nil]; 
// Get size attribute 
NSNumber* fileSizeObj = [attributeDict objectForKey:NSFileSize]; 
long long fileSizeVal = [fileSizeObj lonLongValue]; 
+0

感谢您的重播,但我有一个问题,我可以得到文件的创建日期? – milanjansari 2010-03-19 09:32:52

+0

看到这个问题 - http://stackoverflow.com/questions/1140696/cant-get-filecreationdate,这个键可能在iPhoneOS中不被支持 – Vladimir 2010-03-19 10:09:14