Windows and ctime / st_ctime
Asked Answered
L

1

8

Does Windows offer anything like POSIX stat's st_ctime field, which gives the timestamp of last metadata change?

Background: I have some data files that I'd like to check if they've been modified since a particular timestamp. Checking the modified timestamp (mtime) is easy and takes care of "normal" modifications, but if the user copies over older versions of the data files, then the modified timestamp will show that they're older. On a POSIX system, copying over an older file would result in ctime being newer, even if mtime is older.

Largely answered 19/9, 2012 at 13:29 Comment(0)
L
4

As far as I can tell, Windows does provide a "last changed" field, but I haven't found any Win32 API for accessing it, so you have to use the Native API.

Specifically: (I haven't actually tried this.)

Using the Native API isn't exactly straightforward. This question and answer describe how to do it.

Cygwin takes advantage of this to provide POSIX semantics under Windows, as discussed on their mailing list. I'm getting my information from their implementation.

And although it's only tangentially related, this article has a good description of the "created" timestamp that Windows does present (and unfortunately refers to as ctime). The created timestamp can be newer than the modified timestamp if a file is copied to a new location (since created then refers to when the copy was created, while modified refers to when the original was last modified), but it otherwise is not updated when metadata is changed.

Largely answered 29/8, 2013 at 21:49 Comment(1)
Thanks, yes, that's what @piscisaureus ended up doing in libuv. ctime is now implemented with the Unix semantics (aka, "correctly") in libuv: github.com/joyent/libuv/commit/… Even though this answer came in after we'd already found it, awarded the bounty because you've helped future searchers find the correct answer :)Tanika

© 2022 - 2024 — McMap. All rights reserved.