Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Deleting a File in Windows

by Marshall (Canon)
on May 05, 2009 at 17:50 UTC ( #761995=note: print w/replies, xml ) Need Help??

in reply to Deleting a File in Windows

Good suggestions from other Monks. Here is a bit more detail on the "file is open" case...A file is just a collection of bits on the disk and a directory entry is just a name associated with those bits. What unlink does is remove that name from the directory - it does not delete bits on the disk.

"Deleting/Replacing" a file that is in use is a common scenario for say a software upgrade program that is mucking with a shared file like a .dll. If a file like that is open, you can't just copy over it. The way to deal with that is to rename the file, then delete unlink that new name. Then copy in the new say .dll file that has same name as the original. Once a file is open the directory name is irrelevant as the program is using a file handle.

What happens is that anybody who had that file open continues to use the "original set of bits" that were associated with that name. New opens happen to the new "set of bits". The space on the disk that the "original bits" are in won't be freed until everybody using that file closes it.

Anyway, unlink() can do things that you can't do from the Windows command line with del. From the command line you will see something like "file is use" and del will fail. This won't happen with unlink() even on Windows! I suspect that your permissions are wrong or some such thing and that checking the status return will show something.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://761995]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2022-01-19 10:00 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (55 votes). Check out past polls.