如何设置文件的修改时间编程? [英] How to set the modification time of a file programmatically?

查看:263
本文介绍了如何设置文件的修改时间编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置一个文件的修改时间编程在Windows?

How do I set the modification time of a file programmatically in Windows?

推荐答案

Windows(或标准的CRT,无论如何)具有相同的出现UTimes 家庭的函数,UNIX了。

Windows (or the standard CRT, anyhow) has the same utimes family of functions that UNIX has.

struct _utimebuf t;
t.tma = 1265140799;  // party like it's 1999
t.tmm = 1265140799;
_utime(fn, &t);

使用Win32函数, FILE_BASIC_INFO 可使用的SetFileInformationByHandle

FILE_BASIC_INFO b;
b.CreationTime.QuadPart = 1265140799;
b.LastAccessTime.QuadPart = 1265140799;
b.LastWriteTime.QuadPart = 1265140799;
b.ChangeTime.QuadPart = 1265140799;
b.FileAttributes = GetFileAttributes(fn);
SetFileInformationByHandle(h, FileBasicInfo, &b, sizeof(b));

这篇关于如何设置文件的修改时间编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆