Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Check whether the file is in use by an other user

by wazoox (Prior)
on Jul 30, 2009 at 11:03 UTC ( #784569=note: print w/replies, xml ) Need Help??


in reply to Check whether the file is in use by an other user
in thread Using Win32::OLE and Excel - Tips and Tricks

IIRC Windows locks the file when opened. You may be able to check the file lock state, maybe something like this (I have no windows box to test):
open my $fh, "/some/file" or die "can't open!"; # try/catch file locking eval { flock $fh, 'LOCK_EX' or die "can't lock!" }; if ( $@) { warn "open file!" && exit; }

Replies are listed 'Best First'.
Re^2: Check whether the file is in use by an other user
by fish (Novice) on Jul 30, 2009 at 12:42 UTC
    Thanks for your response. I tried your code and it's not bad but not exactly what I expected. Instead of showing an error-message if the file is opened the program waits until the file is getting closed. That is not bad, but kind of useless for my problem.

    I am sure we are pretty near to a solution, so can somebody tell me how it works - please ;)

    Best regards,
    - fish
      See the flock documentation to check the various (and numerous) available flags, there is probably one of them that'll do what you want :) BTW you really should have posted this in its own thread, because it's a problem completely unrelated to the scope of this tutorial.
      For those of you who are interessted in the topic. I solved the problem by myself.

      sysopen(FH, $file, O_WRONLY|O_EXCL) or die $!; works fine for me and it even works if the file is opened via a shared folder.

      Finally I want to apologize for my offtopic-postings. I thougt the "fileInUse"-check would be possible with a Win32::OLE-function and because of that I posted here and did not create a new thread. I hope I will do better in future.

      Best regards from sunny Germany.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://784569]
help
Chatterbox?
LanX it reeks.
[Your Mother]: You know what they say, the reeky wheel gets the best price at cheese market.
[Eily]: well I had to google translate that
[Eily]: let me inform you that the Dutch reek translate into the Czech páchnout
[Eily]: very useful default translation :P
[Eily]: BTW LanX, you should try typing a few random chars at the beginning of each message. This will prevent expansion :P
[LanX]: qwiud you sthink so?
[LanX]: zxwqbd good idea! :)
LanX embraces his new habit spqopiwjdnq
[ambrus]: qQUkZTmHTuKxStGT- BzTIK9gdudif7TkTLI t3mnF144UaAZjkknXY 8nN-QM19wHBsTrp5vB lEYU_Kksa7X1RIBB4x EWLD5X7SW3jGX5ryfN OMn_yL5FTdQxzjhtyX mKN9sjUCzBNHK5Rrp0 S2WMUvIb1i9aZFgjtq VR0GH1bjPMvm1G16iz hBqc1U6toPd4FbJOFj VsOeT745AN1_pO88rD SRAYKtBZwCZedESZmN mvutrOTHiSNwflB- pRfn_k

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2017-03-27 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.