# How do I know when a file is fully created

**URL:** <https://www.ruby-forum.com/t/how-do-i-know-when-a-file-is-fully-created/121540>\
**Category:** Rails\
**Created:** [November 28, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/how-do-i-know-when-a-file-is-fully-created/121540 "2007-11-28T20:07:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/how-do-i-know-when-a-file-is-fully-created/121540/1 "2007-11-28T20:07:59Z")

</div>

Hi,

I have a rails app, that lets user submit data. I use the data to tell  
another app to create a file. I can’t get this app to tell me when it  
is finished with the file. So is there any way in Rails to check if  
another app is writing to a file?

Kind regards,  
Dave.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2007, 8:20pm UTC](https://www.ruby-forum.com/t/how-do-i-know-when-a-file-is-fully-created/121540/2 "2007-11-28T20:20:19Z")

</div>

> I have a rails app, that lets user submit data. I use the data to tell  
> another app to create a file. I can’t get this app to tell me when it  
> is finished with the file. So is there any way in Rails to check if  
> another app is writing to a file?

There’s probably a way… the unix command lsof will report that sort of  
thing to you, but to check on files you don’t own requires you to be  
root.

So maybe not.

I had to do something similar, but for remote web files. I ended up  
making HEAD requests and comparing the file size over a period of time.  
Once it stopped changing I’d consider the file ready.

You maybe could do something similar.

Or change the process so your second app doesn’t see the file until it’s  
ready. That is, first app writes out “file.tmp” and at the very end  
moves  
it to “file” and second app only looks for “file” or something.
