Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: Deleting a File in Windows by Marshall
in thread Deleting a File in Windows by deadpickle

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2022-01-28 16:40 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (73 votes). Check out past polls.