Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get last file modification date of application data files?

I have a plist file in my application data that i want to update from a webserver every 24 hours. Is there a way to check when the file is last modified or should i, in some way register the date and time when i update the file, and use that to compare to?

if (lastMod > currentDate){
    [arrayFromXml writeToFile:path atomically:YES];
}
like image 557
ebsp Avatar asked Feb 20 '12 17:02

ebsp


People also ask

How do I find the last modified date of a file?

The File. lastModified read-only property provides the last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.

Which command gives information about time of last modification done on file?

ls command ls – Listing contents of directory, this utility can list the files and directories and can even list all the status information about them including: date and time of modification or access, permissions, size, owner, group etc.


1 Answers

You can use NSFileManager for this:

NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:@"path/to/my/file" error:nil];

NSDate *date = [attributes fileModificationDate];

// compare 'date'
// date > now
if ([date compareTo:[NSDate date]] == 1) 
{
    [arrayFromXML writeToFile:@"path/to/my/file" atomically:YES];
}
like image 56
Richard J. Ross III Avatar answered Sep 27 '22 20:09

Richard J. Ross III