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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With