Is there an efficient way to update the last modified property of a file on the iPad's filesystem i.e. the unix touch command?
I've had a look at NSFileManager but no luck.
By default, touch sets both the date of last file modification and the date of last file access to the current time. It maintains the correct release times for software and is useful with the make command.
We can use one of the touch command's option -r (reference) to preserve file timestamps after editing or modifying it. The -r option is used to set the timestamps of one file to the timestamp values of another. As stated already, if we change the contents or metadata of this file, the timestamps will also change.
Modified Time. The modified timestamp contains the time the file's data has been changed. It means when we make changes to the actual contents of the file, the file system will update the modification time.
touch cannot overwrite the contents of an existing file, but the redirect will. If boot. txt does not exist, it is created.
OK, so I'm answering my question just after I've asked it :(
I've found the method setAttributes:ofItemAtPath:error: in the NSFileManager class and I can specify the modified timestamp there.
Thanks anyway!
To update the modification timestamp (which is, for example, shown in the output of ls -l
) of filePath
to now:
NSError* error;
NSFileManager* fileManager = [NSFileManager defaultManager];
if (![fileManager setAttributes:@{NSFileModificationDate:[NSDate date]}
ofItemAtPath:filePath
error:&error]) {
NSLog(@"Couldn't update modification date: %@", error);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With