Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

File::Copy - locked files

by packetstormer (Monk)
on Feb 11, 2013 at 15:58 UTC ( #1018170=perlquestion: print w/replies, xml ) Need Help??

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!


      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.


        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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1018170]
Approved by Ratazong
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2019-08-18 17:00 GMT
Find Nodes?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?

    Results (135 votes). Check out past polls.