2010-03-19 71 views
0

如何使用xcode獲取pdf,gif,doc等文件的大小。 假設我得到PDF文件形式resorce文件夾,所以我怎麼能得到這個文件的大小。獲取文件屬性

有什麼辦法嗎?

謝謝你,

回答

2

如果要計算你的資源文件在運行時的大小基本上你可以做以下(省略錯誤檢查等):

// 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