2010-11-10 68 views
0

Possible Duplicate:
iPhone - file propertiesiPhone - 文件屬性

大家好。我創建一個應用程序,使iphone作爲一個便攜式文件共享目的工作。

在第一階段,我在目錄中有一些文件(png,pdf,jpg,zip),並且我使它們以可變數組形式顯示在tableview中,沒有每個文件的擴展名。

在第二階段中,我有一個detailedViewController的屏幕上顯示文件等的詳細視圖

  1. 文件大小
  2. 文件類型
  3. 如果它是一個圖象,它應在的ImageView
  4. 打開
  5. ,如果它是一首歌,應該發揮它

所以我需要檢索文件路徑一樣的屬性,菲力ype,fileSize ..的每個文件。現在我陷入了獲得像fileSize和fileType這些屬性...請幫我做一個示例源代碼。

這是我的代碼。

- (void)listFiles { 

NSFileManager *fm =[NSFileManager defaultManager]; 
NSError *error = nil; 
NSString *parentDirectory = @"/Users/akilan/Documents"; 
NSArray *paths = [fm contentsOfDirectoryAtPath:parentDirectory error:&error]; 
if (error) { 
    NSLog(@"%@", [error localizedDescription]); 
    error = nil; 
} 
directoryContent = [[NSMutableArray alloc] init]; 
for (NSString *path in paths){ 
    documentsDirectory = [[path lastPathComponent] stringByDeletingPathExtension]; 
    NSLog(@"%@", documentsDirectory); 
    [directoryContent addObject:documentsDirectory]; 

} 

在此先感謝..

回答

1

你應該用你的文件管理器實例的方法attributesOfItemAtPath:error:
看看documentation

+0

好的。當我使用方法attributesOfItemAtPath:error:時,它顯示控制檯中每個文件的可用詳情。我如何檢索特定文件的特定細節?例如,我需要創建第二個文件的日期。我怎樣才能得到它? – iOS 2010-11-10 14:38:29