# Is this file locked?

**URL:** <https://www.ruby-forum.com/t/is-this-file-locked/119763>\
**Category:** Ruby\
**Created:** [November 10, 2007, 5:40am UTC](https://www.ruby-forum.com/t/is-this-file-locked/119763 "2007-11-10T05:40:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ESMark\_Ping](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/d26b3c/32.png) [@ESMark\_Ping](https://www.ruby-forum.com/u/ESMark_Ping)\
**Post date:** [November 10, 2007, 5:40am UTC](https://www.ruby-forum.com/t/is-this-file-locked/119763/1 "2007-11-10T05:40:41Z")

</div>

Is there an easy ruby way to tell if a file is locked? I can lock a  
file using File.flock, but I have a file which may have a shared lock  
and I don’t want to mess with it unless no one else is locking it (and  
grabbing an exclusive lock screws up the program that’s creating the  
file).

I’m on WinXP, so a solution using WIN32API would be acceptable.
