获取文件上次修改时间和比较 [英] Get File Last Modify Time and Compare
问题描述
我想要一个函数,它将采取一个文件,并持续多少天,如果它比这个日期,将返回0否则1 ...这样的东西...
例如:
int IsOlder(TCHAR * filename,int days)
{
执行操作。
如果最后修改日期早于days变量
return 0
else
return 1
}
它是MS VC ++ 6的Windows。
现在感谢!
Windows有一个API函数 GetFileTime code>( MSDN上的文档)采取文件句柄in参数和3
FILETIME
结构中填充日期时间信息:
FILETIME creationTime,
lpLastAccessTime,
lastWriteTime;
bool err = GetFileTime(h,& creationTime,& lpLastAccessTime,& lastWriteTime);
if(!err)error
FILETIME
结构被混淆,使用函数 FileTimeToSystemTime()
将其转换为 SYSTEMTIME
结构,更容易使用:
SYSTEMTIME systemTime;
bool res = FileTimeToSystemTime(& creationTime,& systemTime);然后你可以使用字段
if(!res)error
, wMonth
等与您的天数比较。
I want a piece of function which will take a file and last how many days, if it was older than that date, will return 0 otherwise 1... Something like that...
For example:
int IsOlder(TCHAR *filename, int days)
{
do operation.
If last modify date was older than days variable
return 0
else
return 1
}
It's MS VC++ 6 for Windows.
Thanks from now!
解决方案 Windows has an API function called GetFileTime()
(doc on MSDN) taking a file handle in parameter and 3 FILETIME
structures to be filled with date-time info:
FILETIME creationTime,
lpLastAccessTime,
lastWriteTime;
bool err = GetFileTime( h, &creationTime, &lpLastAccessTime, &lastWriteTime );
if( !err ) error
The FILETIME
structure is obfuscated, use the function FileTimeToSystemTime()
to translate it to a SYSTEMTIME
structure which is way easier to use:
SYSTEMTIME systemTime;
bool res = FileTimeToSystemTime( &creationTime, &systemTime );
if( !res ) error
Then you can use fields wYear
, wMonth
, etc. to compare with your number of days.
这篇关于获取文件上次修改时间和比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!