Is the update date for iOS files updated?

I am trying to determine if (and when) a file was in my file directory of temp files, but the change date ( NSFileModificationDatein the file attributes) seems to always match the creation date ( NSFileCreationDate). I have some vague recollection that the file system in iOS does not update date dates, but I did not find anything documented anywhere.

Can someone confirm (and possibly point to the documentation) that iOS is not updating the change dates?

Also, is there any other method to determine if a file has changed before hashing the contents and tracking the result?

+3
source share
1 answer

, . :

+ (NSDate*) getModificationDateForFileAtPath:(NSString*)path {
    struct tm* date; // create a time structure
    struct stat attrib; // create a file attribute structure

    stat([path UTF8String], &attrib);   // get the attributes of afile.txt

    date = gmtime(&(attrib.st_mtime));  // Get the last modified time and put it into the time structure

    NSDateComponents *comps = [[NSDateComponents alloc] init];
    [comps setSecond:   date->tm_sec];
    [comps setMinute:   date->tm_min];
    [comps setHour:     date->tm_hour];
    [comps setDay:      date->tm_mday];
    [comps setMonth:    date->tm_mon + 1];
    [comps setYear:     date->tm_year + 1900];

    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDate *modificationDate = [[cal dateFromComponents:comps] addTimeInterval:[[NSTimeZone systemTimeZone] secondsFromGMT]];

    [comps release];

    return modificationDate;
}
+2

All Articles