Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. delete files past a certain date

delete files past a certain date

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    si_69
    wrote on last edited by
    #1

    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)) }

    C L K H 4 Replies Last reply
    0
    • S si_69

      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)) }

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      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 Box

      led mike

      1 Reply Last reply
      0
      • S si_69

        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)) }

        C Offline
        C Offline
        Chris Losinger
        wrote on last edited by
        #3

        si_69 wrote:

        im using the below, but it doesnt seem to be working

        which part isn't working ?

        image processing | blogging

        S 1 Reply Last reply
        0
        • S si_69

          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)) }

          K Offline
          K Offline
          krmed
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • C Chris Losinger

            si_69 wrote:

            im using the below, but it doesnt seem to be working

            which part isn't working ?

            image processing | blogging

            S Offline
            S Offline
            si_69
            wrote on last edited by
            #5

            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 ?

            V 1 Reply Last reply
            0
            • S si_69

              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 ?

              V Offline
              V Offline
              vladfein
              wrote on last edited by
              #6

              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

              S 1 Reply Last reply
              0
              • V vladfein

                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

                S Offline
                S Offline
                si_69
                wrote on last edited by
                #7

                vladfein wrote:

                No, it doesn't. It gives you: 1107590400

                yes it does !

                1 Reply Last reply
                0
                • S si_69

                  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)) }

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #8

                  When you run this code whats happening

                  _**


                  **_

                  WhiteSky


                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups