Alex Rivera | Logout

DeleteFile fails on recently closed file

Asked 2009-11-18T02:20:32.133
11

I have a single threaded program (C++, Win32, NTFS) which first creates a quite long temporary file, closes it, opens for read, reads, closes again and tries to delete using DeleteFile().

Usually it goes smoothly, but sometimes DeleteFile() fails, and GetLastError() returns ERROR_ACCESS_DENIED. File is not read-only for sure. It happens on files on any size, but the probability grows with the file size.

Any ideas what may be locking the file? I tried WinInternals tools to check and found nothing suspicious.

Edit
Report

1 Answer

4

Add a MessageBox() call before you invoke DeleteFile(), When it shows up, run the sysinternals tool Process Explorer. Search for an open handle to the file. In all probability you have not closed all handles to the file...

answered 2009-11-18T02:24:02.323

Your Answer