http://www.perlmonks.org?node_id=1018170

packetstormer has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Would anyone know how, or if, File::Copy deals with open/in use files - specifically on a Windows OS? I am creating an app to backup files/folders but I am concerned about files that are locked or in use.

Has anyone any suggestions?

Replies are listed 'Best First'.
Re: File::Copy - locked files
by ww (Archbishop) on Feb 11, 2013 at 17:11 UTC
    Not a good idea!

    Wait for the lock to be released. Otherwise you may be putting an incomplete or outdated file into your backup collection. As with all backups, shortcomings don't usually get to be a big problem... until you actually need the backup, by which time, it's too late to fix the problem.


    If you didn't program it by toggling in binary, it wasn't programming!

      Agreed!

      What about files that are in use though, continually (or close to). Is there any accepted method for dealing with this type of thing? Suppose it's a small Access database with a lock on it (in use by a Windows service that is always running!). Is there any shadowing copying libraries for Perl!?

        Recent Windows versions have a special service (Volume Shadow Service? Use Google!) for this problems, it allows you to take some kind of snapshot of the filesystem. All modifications after the snapshot do not affect your program, so you can safely copy files from a mounted filesystem. Of course, this service can't guarantee that all open files are in a consistent state.

        Regarding your locked Access database: Shut down the service, then backup or make at least a copy of the database file, then restart the service and exclude the original, locked file.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: File::Copy - locked files
by kennethk (Abbot) on Feb 11, 2013 at 16:32 UTC

    Have you tried copying locked/in use files? Fortune favors the bold.

    C:\>perl -MFile::Copy -e "copy 'file1.txt', 'file2.txt'" C:\>

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.