2012-12-13 94 views
2
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *currDircetory = [documentPath objectAtIndex:0]; 
NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:currDircetory error:nil]; 
for (NSString *s in filePathsArray){ 
     NSLog(@"file %@", s); 
} 

現在我使用上面的代碼從文檔目錄中獲取文件列表,現在我想知道如何獲取文檔目錄中文件的修改時間。在iphone中獲取文檔目錄文件的日期修改時間

感謝,

維賈雅恩

回答

0

你可以得到你的答案Here

但是,只有改變你要做的是,你需要改變NSFileCreationDateNSFileModificationDate

NSDate *date = (NSDate*)[attrs objectForKey: NSFileModificationDate]; 
7
NSFileManager* filemngr = [NSFileManager defaultManager]; 

NSDictionary* attributes = [filemngr attributesOfItemAtPath:path error:nil]; 

if (attributes != nil) { 

    NSDate *date = (NSDate*)[attributes objectForKey:NSFileModificationDate]; 
} else { 

    NSLog(@"File Not found !!!"); 
} 
11

您可以使用此:

NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *currDircetory = [documentPath objectAtIndex:0]; 
NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:currDircetory error:nil]; 

for (NSString *s in filePathsArray){ 

    NSString *filestring = [currDircetory stringByAppendingFormat:@"/%@",s]; 
    NSDictionary *filePathsArray1 = [[NSFileManager defaultManager] attributesOfItemAtPath:filestring error:nil]; 
    NSLog(@"Modified Day : %@", [filePathsArray1 objectForKey:NSFileModificationDate]); 
} 
+4

謝謝ABI,它的工作原理 – user1844142

+1

@ user1844142歡迎!請你接受答案:P –

相關問題