开发者

Setting windows creation date using POSIX api

I have a program (jhead) that compiles with very few tweaks for both Windows and generic Unix variants. From time to time, windows users ask if it can be modified to also set the "creation date/time" of the files, but I don't see a way to do this with the POSIX api. What I'm currently doing is:

{

    struct utimbuf mtime;

    mtime.actime 开发者_开发问答= NewUnixTime;

    mtime.modtime = NewUnixTime;

    utime(FileName, &mtime);

}

Ideally, struct utimebuf would just have a creation time, but it doesn't. It strikes me it would take a lot of windows specific, non-portable code to change the creation time under Windows. Is there another POSIX way of doing this? Any suggestions?


POSIX only recognizes three different file times:

  1. atime (access time): The last time the file was read
  2. mtime (modification time): The last time the file was written
  3. ctime (attribute change time): The last time the file's metadata was modified

Any other file times that may exist in the underlying OS require OS-specific API calls in order to be modified.

And don't worry about creating non-portable code; only these times really exist under most *nix variants.


The Win32 API for this isn't really all that bad, as Windows APIs go: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724933%28v=vs.85%29.aspx . The trickiest thing is to work out how many seconds Windows thinks there were between 1st January 1601 and 1st January 1970; the rest is straightforward.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜