Click here to Skip to main content
15,916,412 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
When we try to delete a file which is in use with certain application then OS throws exception that "cannot delete file". I want to delete such file without terminating associated application.
It can be made possible by loading the file completely into main memory at the start of application.
I have a software "Unlocker" which forces file to delete but it also closes the associated application. I want to delete file from disk without causing the running application to stop. Please post any code (preferably java) to solve this problem. Otherwise tell the link to download such software.
Posted

Hi
It is impossible to unlock a file that is currently locked by another process without terminating the process and/or rebooting your computer (which would terminate the process, so there is no big difference). It is a part of Windows' built-in security mechanism to handle it this way. Or would you be glad if there is a misbehaving app which deletes your currently open, 100 sites big word dokument "by accident"?

cheers,
Marco Bertschi
 
Share this answer
 
As noted in solution #1, this behavior is by design.

Having said that, one way you can sometimes do the same logical thing is to rename the file to a 'to be deleted' directory. The file itself is not deleted, but the filename is freed up, allowing you to create a subsequent file with the same name.

Ability to do this depends on the operating system and 'file open' options specified in the 'other' process. [and of course, file and directory ownership/access settings]
 
Share this answer
 
Comments
Member 8456001 18-Mar-13 5:36am    
Is there disk space available which is user inaccessible but program can store and run stored file and delete that file. User inaccessible means user should not be allowed to view or copy that file. It's required for the purpose of security.
H.Brydon 18-Mar-13 20:29pm    
Not in general, but it depends on the operating system. One way to duplicate that functionality is to create a virtual drive in memory, and do file transactions to the memory drive, including create, execute, delete.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900