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