delete files past a certain date
-
hi i want to delete files past a certain date for example if the file is older than a certain number of days(nDays) remove it im using the below, but it doesnt seem to be working can anyone see whats wrong ?? thanks Si WIN32_FIND_DATA fd; HANDLE hFind = ::FindFirstFile (_T (sPath+sExt), &fd); CString name = fd.cFileName; CTime tmCreate(fd.ftCreationTime); CTime ctNow = CTime::GetCurrentTime(); if(tmCreate < (CTime::GetCurrentTime() - CTimeSpan(nDays,0,0,0))) { CString strFileName = sPath+"\\"+ (CString)fd.cFileName; if(::DeleteFile(strFileName)) }
-
hi i want to delete files past a certain date for example if the file is older than a certain number of days(nDays) remove it im using the below, but it doesnt seem to be working can anyone see whats wrong ?? thanks Si WIN32_FIND_DATA fd; HANDLE hFind = ::FindFirstFile (_T (sPath+sExt), &fd); CString name = fd.cFileName; CTime tmCreate(fd.ftCreationTime); CTime ctNow = CTime::GetCurrentTime(); if(tmCreate < (CTime::GetCurrentTime() - CTimeSpan(nDays,0,0,0))) { CString strFileName = sPath+"\\"+ (CString)fd.cFileName; if(::DeleteFile(strFileName)) }
si_69 wrote:
can anyone see whats wrong ??
Probably someone stepping through that in debug mode would be able to see whats wrong :rolleyes:
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real"
Score: 1.0 in the Soap Boxled mike
-
hi i want to delete files past a certain date for example if the file is older than a certain number of days(nDays) remove it im using the below, but it doesnt seem to be working can anyone see whats wrong ?? thanks Si WIN32_FIND_DATA fd; HANDLE hFind = ::FindFirstFile (_T (sPath+sExt), &fd); CString name = fd.cFileName; CTime tmCreate(fd.ftCreationTime); CTime ctNow = CTime::GetCurrentTime(); if(tmCreate < (CTime::GetCurrentTime() - CTimeSpan(nDays,0,0,0))) { CString strFileName = sPath+"\\"+ (CString)fd.cFileName; if(::DeleteFile(strFileName)) }
si_69 wrote:
im using the below, but it doesnt seem to be working
which part isn't working ?
-
hi i want to delete files past a certain date for example if the file is older than a certain number of days(nDays) remove it im using the below, but it doesnt seem to be working can anyone see whats wrong ?? thanks Si WIN32_FIND_DATA fd; HANDLE hFind = ::FindFirstFile (_T (sPath+sExt), &fd); CString name = fd.cFileName; CTime tmCreate(fd.ftCreationTime); CTime ctNow = CTime::GetCurrentTime(); if(tmCreate < (CTime::GetCurrentTime() - CTimeSpan(nDays,0,0,0))) { CString strFileName = sPath+"\\"+ (CString)fd.cFileName; if(::DeleteFile(strFileName)) }
Not sure if this applies in your case, but according to MSDN:
In rare cases, file attribute information on NTFS file systems may not be current at the time you call this function. To obtain the current NTFS file attributes, call GetFileInformationByHandle.
Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
si_69 wrote:
im using the below, but it doesnt seem to be working
which part isn't working ?
Chris Losinger wrote:
which part isn't working ?
the if statement. the date of the file i wish to delete is 2/5/2005 which gives tmCreate {m_time=1157539835 } and i want to delete files which are older than 11 days olds which gives me a time of {m_time=1156699696 } so the if statement reads if(tmCreate < (CTime::GetCurrentTime() - CTimeSpan(nDays,0,0,0))) i.e {m_time=1157539835 } < {m_time=1156699696 } but how can i file older have a m_time value higher than the time of 11 days ago perhaps thats where its going wrong any ideas ?
-
Chris Losinger wrote:
which part isn't working ?
the if statement. the date of the file i wish to delete is 2/5/2005 which gives tmCreate {m_time=1157539835 } and i want to delete files which are older than 11 days olds which gives me a time of {m_time=1156699696 } so the if statement reads if(tmCreate < (CTime::GetCurrentTime() - CTimeSpan(nDays,0,0,0))) i.e {m_time=1157539835 } < {m_time=1156699696 } but how can i file older have a m_time value higher than the time of 11 days ago perhaps thats where its going wrong any ideas ?
si_69 wrote:
the date of the file i wish to delete is 2/5/2005 which gives tmCreate {m_time=1157539835 }
No, it doesn't. It gives you: 1107590400
----------------------------- Get trial copy of FeinViewer - an integrated GDI objects viewer for Microsoft Visual Studio .NET 2005 (8.0) Visual C++ Debugger, and other convenience and productivity tools for Microsoft Visual Studio .NET at at www.FeinSoftware.com
-
si_69 wrote:
the date of the file i wish to delete is 2/5/2005 which gives tmCreate {m_time=1157539835 }
No, it doesn't. It gives you: 1107590400
----------------------------- Get trial copy of FeinViewer - an integrated GDI objects viewer for Microsoft Visual Studio .NET 2005 (8.0) Visual C++ Debugger, and other convenience and productivity tools for Microsoft Visual Studio .NET at at www.FeinSoftware.com
-
hi i want to delete files past a certain date for example if the file is older than a certain number of days(nDays) remove it im using the below, but it doesnt seem to be working can anyone see whats wrong ?? thanks Si WIN32_FIND_DATA fd; HANDLE hFind = ::FindFirstFile (_T (sPath+sExt), &fd); CString name = fd.cFileName; CTime tmCreate(fd.ftCreationTime); CTime ctNow = CTime::GetCurrentTime(); if(tmCreate < (CTime::GetCurrentTime() - CTimeSpan(nDays,0,0,0))) { CString strFileName = sPath+"\\"+ (CString)fd.cFileName; if(::DeleteFile(strFileName)) }
When you run this code whats happening
_**
**_
WhiteSky