Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Deleting a File in Windows

by Marshall (Canon)
on May 05, 2009 at 17:50 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found