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);
}

Now i used the above code to get list of file from document directory now i want to know how to get modified time of the file in document directory.

Thanks,

Vijayan

MadhuP
  • 2,019
  • 17
  • 22

3 Answers3

11

You can use this :

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]);
}
abi
  • 819
  • 2
  • 9
  • 24
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 !!!");
}
Abi
  • 958
  • 1
  • 7
  • 22
0

You can get your answer Here.

But only change you going to do is, you need to change NSFileCreationDate to NSFileModificationDate

NSDate *date = (NSDate*)[attrs objectForKey: NSFileModificationDate];
Community
  • 1
  • 1
arthankamal
  • 6,341
  • 4
  • 36
  • 51