Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

windows

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 if an antivirus hits the wrong file at the wrong time, some random program might misbehave and possibly crash.

Am I right? Are there plans to fix this?

Do any of you find this acceptable, or, how could it possibly seem a good idea at the time?

Edit:

It works very differently on Unix, and has been so for decades.

As an example:

  • process 1 opens foo.txt, for read or write, or both, doesn't matter
  • process 2 deletes the file
  • the file is unlinked from the filesystem
  • process 1 keeps reading and/or writing, the file still exists, and it can grow as long as there's room on the disk. It's just not reachable from other processes that have not already a file handle to it.
  • when process 1 closes the file, it won't be accessible from anywhere

Actually, a common usage pattern for temporary files on Unix is: open-remove-read/write-close.

like image 789
Marco Mariani Avatar asked Jul 08 '10 09:07

Marco Mariani


People also ask

Can an open file be deleted?

If the file you want to delete is in an “exe” file of a program, try closing the program first, then attempt to delete the file again. You can also try restarting your PC to close down any running programs or closing the apps that might be using the program you want to delete.

Can't delete file is open in system?

End the Application via the Task Manager This is the most promising method to fix the "file is open in another program" error. Click Ctrl + Shift + ESC to open the Task Manager. Alternatively, you can press Ctrl + Alt + Del or right-click the Taskbar and select Task Manager.

How do you force delete a file that is open?

In the command window, type the DEL /F file name command and press Enter to force delete the file that is in use.


1 Answers

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.

like image 126
mafu Avatar answered Nov 16 '22 00:11

mafu