Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Detecting locked files in Windows

by moggs (Sexton)
on Mar 25, 2008 at 15:52 UTC ( [id://676149]=perlquestion: print w/replies, xml ) Need Help??

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

Hi... this should (in theory) be an easy question...

Is there any way I can detect a locked file in Windows? I've done my searches, but don't seem to have found anything positive.

The tiny little task I've been given is to zip and FTP all the data in a number of directories created by an accounting package, but it must fail (or at least warn) if any of the files are locked.

Ideas would be warmly appreciated... even just the next set of search terms!

Many thanks! Moggs

Replies are listed 'Best First'.
Re: Detecting locked files in Windows
by dragonchild (Archbishop) on Mar 25, 2008 at 16:07 UTC
    Try to see if you can take a lock on it. If you can't, it's locked.
    use Fcntl ':flock'; if ( flock( $filename, LOCK_EX | LOCK_NB ) ) { # File is unlocked flock( $filename, LOCK_UN ); } else { # File is locked. }

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Detecting locked files in Windows
by stiller (Friar) on Mar 25, 2008 at 16:10 UTC
    by convention, ms office creates a "lockfile" whose presence tells ms office that the file is locked. The "lockfile" gets a name that relates to the original name like ~$est.doc to test.doc Also, see File locking

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-26 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found