Figured it out. Here is the code if anyone is interested. Not sure if there is a better way, but this does what I need it to do so I'll stick with it.
Code:
#include "stdafx.h"
#include <string>
#include <windows.h>
#include <time.h>
#include <map>
#include <iostream>
#define path "C:\\temp\\"
struct file_data
{
std::wstring sLastAccessTime;
__int64 nFileSize;
};
_int64 Delta(const SYSTEMTIME st1, const SYSTEMTIME st2)
{
union timeunion {
FILETIME fileTime;
ULARGE_INTEGER ul;
} ;
timeunion ft1;
timeunion ft2;
SystemTimeToFileTime(&st1, &ft1.fileTime);
SystemTimeToFileTime(&st2, &ft2.fileTime);
return ft2.ul.QuadPart - ft1.ul.QuadPart;
}
SYSTEMTIME convertTM2SYSTEMTIME(struct tm *tmTime, SYSTEMTIME *systemTime)
{
systemTime->wDay = tmTime->tm_mday;
systemTime->wDayOfWeek = tmTime->tm_wday;
systemTime->wMonth = tmTime->tm_mon + 1;
systemTime->wYear = tmTime->tm_year + 1900;
systemTime->wHour = tmTime->tm_hour;
systemTime->wMinute = tmTime->tm_min;
systemTime->wSecond = tmTime->tm_sec;
systemTime->wMilliseconds = 0;
return *systemTime;
}
int GetFileList(const wchar_t *searchkey, std::map<std::wstring, file_data> &map)
{
WIN32_FIND_DATA fd;
HANDLE h = FindFirstFile(searchkey,&fd);
wchar_t bufA[128], szBuff[128];
if(h == INVALID_HANDLE_VALUE)
{
return 0;
}
while(1)
{
char szBuffer[512];
//Get current date & time info
unsigned int value;
time_t rawtime;
struct tm * ptm;
time(&rawtime);
ptm = gmtime(&rawtime);
SYSTEMTIME mySysTime;
convertTM2SYSTEMTIME(ptm ,&mySysTime);
//File Time Info
FILETIME ft = fd.ftLastWriteTime;
SYSTEMTIME sysTime;
FileTimeToSystemTime(&ft, &sysTime);
//Difference in times
_int64 i = Delta(mySysTime, sysTime);
//Convert to positive integer
i = ((i / 10000000) * -1);
file_data filedata;
filedata.sLastAccessTime = bufA;
filedata.nFileSize = (((__int64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;
map[fd.cFileName]= filedata;
std::wcout << fd.cFileName << std::endl;
//Check if the date is older than 1 day
if(i < 86400)
{
std::wcout << i << " is less than 86400" << std::endl;
}
else if(i > 86400)
{
std::wcout << i << " is greater than 86400" << std::endl;
sprintf(szBuffer, "del %s%s /F /Q", path, &map);
system(szBuffer);
}
if(FindNextFile(h, &fd) == FALSE)
break;
}
return map.size();
}
int main()
{
std::map<std::wstring, file_data> map;
GetFileList(L"C:\\temp\\*.*", map);
for(std::map<std::wstring, file_data>::const_iterator it = map.begin(); it != map.end(); ++it)
{
//std::wcout << it->first.c_str() << std::endl;
}
Sleep(10000);
return 0;
}