Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Is it possible to update a file without modifying its ctime?
-
Sorry if my topic seems unclear but I'm coming from the world of IBM's main frame.
If I correctly understand, under Unix, ctime attribute of a file is not the creation date/time but the date/time of last change of an attribute, and if we modify a file, we modify its mtime, thus an attribute, thus its ctime also.
And IOS comes from the same kernel as Unix...
Thus my question is: is it possible to update/modify a file (in place) without modifying its ctime? -
I'm not sure about when exactly the
ctime
is updated. There is anos.utime
function that can be used to change theatime
andmtime
(but not thectime
), so you could use that to preserve the access/modification times. -
Thanks for spending your time.
I know utime but I want to know if it's possible to keep the real creation time. -
The question is for what you need this. If you want to preserve
ctime
value even when you modify file content / metadata, then there's no way. But if you want to know real time when the file was created,fstat64
&birthtime
(notctime
) is your friend. OrNSFileCreationDate
attribute on iOS 64-bit (NSFileManager.attributesOfItemAtPath:error:
). -
@zrzka I only want to know the creation date/time, thus this birthtime should be what I need, but I don't understand how to use it. Thanks for your help
-
Copy & paste this script to your Pythonista and run it.
from objc_util import ObjCClass import editor NSFileManager = ObjCClass('NSFileManager') NSFileCreationDate = 'NSFileCreationDate' attrs = NSFileManager.defaultManager().attributesOfItemAtPath_error_(ns(editor.get_path()), None) creation_date = attrs[NSFileCreationDate] print('File name: {}'.format(editor.get_path())) print('File creation date: {}'.format(creation_date)) print('File creation timestamp: {}'.format(creation_date.timeIntervalSince1970()))
Console output
File name: /private/var/mobile/Containers/Shared/AppGroup/6644AB67-CC6B-4108-B96C-5DCDAC15FB7C/Pythonista3/Documents/birthtime.py File creation date: 2017-08-11 14:55:52 +0000 File creation timestamp: 1502463352.8284547
-
@zrzka "ns not defined" error, but if I replace ns(...) by a file name, it's ok.
Thanks a lot for your help.Ok, I also imported ns 😅
-
That's how Pythonista works. Always forgot to reset env before testing and some of these things are already imported. Glad you fixed it by yourself :)
-
Analyze (pyflakes)
in the wrench menu can help you to see these issues.