Will we ever be able to delete an open file in Windows?

前端 未结 2 1684
悲哀的现实
悲哀的现实 2020-12-06 10:16

Disclaimer: I am mainly a linux/web developer.

Windows has this \"nice\" feature where it denies permission to delete any file that is held open by any process. So i

相关标签:
2条回答
  • Your initial statement is not correct. Windows does allow open files to be deleted. You just have to specify FILE_SHARE_DELETE and you're all set. Careful programmers should sensibly decide if that flag (or sharing for reading/writing) make sense and pass it.

    An anti virus product that does not open files with full sharing (including deletion) enabled is buggy.

    Windows does, however, remember the current working directory of any process and prevents it from being deleted. This working directory is independent of the location of any files opened by the process.

    0 讨论(0)
  • 2020-12-06 10:54

    This is perfectly acceptable. Imagine a situation where you're reading a database file in your application, and some other application comes along and deletes that database file from right under you. How does your application know to check that the file still exists? How will it ensure that the file stream does not all of a sudden attempt to read that file may be there one millisecond, but not the next? This is why programs can lock files, to ensure that the file will always be there until the program determines that it is done with it.

    It may be more helpful to tell us why this file locking is undesirable in your situation. I'm pretty sure anti-virus programs do an optimistic lock on files, unless it's cleaning them.

    0 讨论(0)
提交回复
热议问题