INFO: DeleteFile Fails if File is Open

ID: Q225343

This article discusses a Beta release of a Microsoft product. The information in this article is provided as-is and is subject to change without notice.

No formal product support is available from Microsoft for this Beta product. For information about obtaining support for a Beta release, please see the documentation included with the Beta product files, or check the Web location from which you downloaded the release.
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API), included with:
    • Microsoft Windows 2000


SUMMARY

The Win32 API DeleteFile function fails if an application attempts to delete a file that is open for normal I/O or as a memory-mapped file. This is true for all versions of Windows NT.


MORE INFORMATION

In the Windows 95 and 98 environment, the DeleteFile function deletes a file even if it is open unless the file has been opened with the FILE_SHARE_DELETE flag. Because deleting open files may cause loss of data and application failure, make sure to close a file before attempting to delete it.

If the file has been opened with the FILE_SHARE_DELETE flag, the DeleteFile function will succeed, but the file will not actually disappear until the last handle to the file has been closed.

Additional query words: compatguidediff

Keywords : kbWinOS2000 kbGrpKernBase
Version : winnt:
Platform : winnt
Issue type : kbinfo


Last Reviewed: May 25, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.