in reply to Re^3: Deleting or unlinking a file
in thread Deleting or unlinking a file

del X, unable to delete file X, file is in use. However the Perl unlink 'X' command will succeed.

Its been a while since I played with FAT/FAT32, but NTFS won't let you unlink a dll

Replies are listed 'Best First'.
Re^5: Deleting or unlinking a file
by Marshall (Canon) on Mar 16, 2011 at 01:16 UTC
    This was on W2K Server which is NTFS. I don't know about FAT32 and how that might or might not work. That's a "dead" file system anyway. Yes, there are some implementation details about this and my memory is a bit foggy. I think that I might have had to rename the .dll and then unlink it. But I was able to get an "in use" .dll name removed from the directory and replaced with a new file without affect upon currently running processes.

    Didn't mean to write a tutorial on software update - the main point is that "unlink" does something different than "delete". And that it is definitely possible to "unlink" a file that is currently in use because the "human text name" is not how the file system deals with the file, if the file is "open" and being accessed via the file handle. The actual "deletion" occurs when the file is no longer in use.

    Of course in the scheme that I described, there are significant complications in the implementation of how a potentially very long lived process gets notified of this update and how it should go about dealing with it. This whole "update" scenario can become very complicated. However, I am confident that Perl unlink can make things happen that the Windows command line would not allow.

      However, I am confident that Perl unlink can make things happen that the Windows command line would not allow.

      What?

        I did some testing on my XP machine. I guess one moral of this story is not to have confidence in any Microsoft OS or file system behavior!

        WinXP home does not work like I remember W2K Server working - but this was many years ago. Anyway the unlink doesn't work like I expected, at least not on my home XP system. What happens on XP server versions, Win 7 and others, I don't know and have no way to test. I only have one user who still runs W2K and I deal with this guy on a case by case basis. I lost a hard drive and dismantled my W2K system years ago.

        I don't know about others, but for me it can become very confusing as to what works on what version of MS OS and NTFS file system versions.

        I did investigate this issue a bit further and found that there is an XP utility InUse.exe which apparently can replace a file that is in use. Many installation programs register a "run once" program than runs during the next reboot and before Windows fully starts. Anyway, I figure that there is a way to do what I described, but not in the way that I described it, at least not on XP home. Ooops.