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. DeleteFile() Function Failure

DeleteFile() Function Failure

Scheduled Pinned Locked Moved C / C++ / MFC
c++debuggingquestion
5 Posts 5 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.
  • D Offline
    D Offline
    Donguy1976
    wrote on last edited by
    #1

    Hey there In my VC++ application i see that this function fails in certain times, but was not able to reproduce it. So am trying to debug and have few questions. Does the DeleteFile() fails if multiple files are deleted quickly inside a loop and if some files are larger in size? What other possible causes can lead to DeleteFile() to fail?

    T L H E 4 Replies Last reply
    0
    • D Donguy1976

      Hey there In my VC++ application i see that this function fails in certain times, but was not able to reproduce it. So am trying to debug and have few questions. Does the DeleteFile() fails if multiple files are deleted quickly inside a loop and if some files are larger in size? What other possible causes can lead to DeleteFile() to fail?

      T Offline
      T Offline
      thanh_bkhn
      wrote on last edited by
      #2

      There are some reasons lead to DeleteFile() failure: 1. File not found 2. Path not found 3. Access denied The first two reason maybe avoidable, but when you delete a large amount of file, depending on the disk status, there is a possibility that the access error happens. I also encountered this error when manually delete a directory which contains a large amount of files and sub directories, so I have to retry several times. If you use DeleteFile() in your program, I think you should use catch and retry deleting several times before give it up.

      "Never memorize something that you can look up." - Albert_Einstein

      1 Reply Last reply
      0
      • D Donguy1976

        Hey there In my VC++ application i see that this function fails in certain times, but was not able to reproduce it. So am trying to debug and have few questions. Does the DeleteFile() fails if multiple files are deleted quickly inside a loop and if some files are larger in size? What other possible causes can lead to DeleteFile() to fail?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Donguy1976 wrote:

        What other possible causes can lead to DeleteFile() to fail?

        If the call fails then you can find the reason by calling GetLastError(), as described in the documentation[^].

        Use the best guess

        1 Reply Last reply
        0
        • D Donguy1976

          Hey there In my VC++ application i see that this function fails in certain times, but was not able to reproduce it. So am trying to debug and have few questions. Does the DeleteFile() fails if multiple files are deleted quickly inside a loop and if some files are larger in size? What other possible causes can lead to DeleteFile() to fail?

          H Offline
          H Offline
          hans sch
          wrote on last edited by
          #4

          From the MSDN documentation of DeleteFile:

          If the function fails, the return value is zero (0). To get extended error information, call GetLastError.

          GetLastError returns an error code which you can convert into a string via the FormatMessage function. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms680582%28v=vs.85%29.aspx[^] for an example. One possible reason might be that you are trying to delete the same file more than once.

          1 Reply Last reply
          0
          • D Donguy1976

            Hey there In my VC++ application i see that this function fails in certain times, but was not able to reproduce it. So am trying to debug and have few questions. Does the DeleteFile() fails if multiple files are deleted quickly inside a loop and if some files are larger in size? What other possible causes can lead to DeleteFile() to fail?

            E Offline
            E Offline
            Erudite_Eric
            wrote on last edited by
            #5

            Donguy1976 wrote:

            What other possible causes can lead to DeleteFile() to fail?

            Well, the blindingly obvious are: 1) It doesnt exist. 2) Somthing else has it open. The less obvious is that your calling code doesnrt have Delete authorisation. Loo ak the error return, it will tell you all about it.

            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