# Changenotify - determine when a file has been closed

**URL:** <https://www.ruby-forum.com/t/changenotify-determine-when-a-file-has-been-closed/135200>\
**Category:** Ruby\
**Created:** [April 19, 2008, 3:26am UTC](https://www.ruby-forum.com/t/changenotify-determine-when-a-file-has-been-closed/135200 "2008-04-19T03:26:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sean\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sean\_n](https://www.ruby-forum.com/u/sean_n)\
**Post date:** [April 19, 2008, 3:26am UTC](https://www.ruby-forum.com/t/changenotify-determine-when-a-file-has-been-closed/135200/1 "2008-04-19T03:26:04Z")

</div>

Is there a way to determine when a file has been closed? I know the  
changenotify module can determine when a file is written to, but I need  
to  
know when it has been closed. The file is a postscript file being  
created  
by a printer driver and I want to make a copy of it when the file is  
done  
being written to.

---

<div class="post-metadata">

**Author:** ![sean\_n](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sean\_n](https://www.ruby-forum.com/u/sean_n)\
**Post date:** [April 20, 2008, 1:10am UTC](https://www.ruby-forum.com/t/changenotify-determine-when-a-file-has-been-closed/135200/2 "2008-04-20T01:10:57Z")

</div>

On Apr 18, 2008, at 7:25 PM, Sean N. wrote:

> Is there a way to determine when a file has been closed? I know the  
> changenotify module can determine when a file is written to, but I  
> need to know when it has been closed. The file is a postscript file  
> being created by a printer driver and I want to make a copy of it  
> when the file is done being written to.

A quick way to do this would be the directory\_watcher gem. It watches  
files in a directory and notifies you when those files change – add,  
modified, deleted. There is a fourth file notification event called  
“stable” – this is sent when the file has remained un-modified for X  
amount of time.

[http://codeforpeople.rubyforge.org/directory\_watcher/](http://codeforpeople.rubyforge.org/directory_watcher/)

It’s all ruby code, so it should work on Windows and Unix equally well.

Blessings,  
TwP
