Reputation: 107
I just want the creation or modification time of the files and compare it with system time.
if (fileExtensions[i] == restoken && lmdCheck.GetCheck() == true)
{
testbox3.AddString(allFiles[i]);
CFileStatus status;
CFile cfile;
//cfile.Open(allFiles[i],NULL,NULL);
cfile.Open(allFiles[i], CFile::modeRead | CFile::modeWrite);
CTime t = CTime::GetCurrentTime();
TRACE(t.Format(L"%X\n"));
SYSTEMTIME SystemTime;
//::GetSystemTime(&SystemTime);
::GetLocalTime(&SystemTime);
CTime SystemT(SystemTime);
TRACE(SystemT.Format(L"%X\n"));
ULONGLONG dwNewLength = 10000;
cfile.SetLength(dwNewLength);
if (cfile.GetStatus(status))
{
if (status.m_ctime < SystemTime)
{
cfile.Close();
CFile::Remove(allFiles[i]);
}
}
}
And delete those file who is less then system time. Please help?
Upvotes: 0
Views: 1294
Reputation: 107
Sorry guys my mistake. I don't want system time i want data and time picker data. I solve my problem with this code.
for (int i = 0; i < allFiles.GetSize(); i++)
{
GetFileExt(allFiles[i]);
CString str, restoken;
fileExt.GetWindowText(str);
int curPos = 0;
restoken = str.Tokenize(_T(" "), curPos);
while (restoken != _T(""))
{
textBox2.AddString(restoken);
int a = fileExtensions.GetSize();
if (fileExtensions[i] == restoken && lmdCheck.GetCheck() == true)
{
testbox3.AddString(allFiles[i]);
CFileStatus status;
CFile cfile;
cfile.Open(allFiles[i], CFile::modeRead | CFile::modeWrite);
if (cfile.GetStatus(status))
{
CTime variable, clDate;
lmdDate.GetTime(clDate);
if (status.m_mtime < clDate)
{
cfile.Close();
CFile::Remove(allFiles[i]);
}
}
}
restoken = str.Tokenize(_T(" "), curPos);
}
Bye the way thank you friends.
Upvotes: 1
Reputation: 31599
This will compare file's FILETIME to current SYSTEMTIME
BOOL get_finddata(const TCHAR *filename, WIN32_FIND_DATA &data)
{
if (!filename) return FALSE;
HANDLE h = FindFirstFile(filename, &data);
if (h == INVALID_HANDLE_VALUE)
return FALSE;
FindClose(h);
return TRUE;
}
void change_filetime(FILETIME &ft, int sec)
{
ULONGLONG temp = (((ULONGLONG)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
temp += sec * __int64(10000000);//100-nanosecond intervals
ft.dwLowDateTime = (DWORD)(temp & 0xFFFFFFFF);
ft.dwHighDateTime = (DWORD)(temp >> 32);
}
void checkfor_older_files(const TCHAR *filename)
{
WIN32_FIND_DATA finddata;
if (!get_finddata(filename, finddata)) return;
//finddata.ftCreationTime;
//finddata.ftLastWriteTime;
//finddata.ftLastAccessTime;
SYSTEMTIME st;
GetSystemTime(&st);
FILETIME comparetime;
SystemTimeToFileTime(&st, &comparetime);
//change comparetime, for example, get files older than 30 minutes
change_filetime(comparetime, -30 * 60);
if (CompareFileTime(&finddata.ftCreationTime, &comparetime) < 0)
OutputDebugString(L"older file\n");
else
OutputDebugString(L"not old\n");
}
Upvotes: 0