# Windows platform, test if a file is fully flushed to disk

**URL:** <https://www.ruby-forum.com/t/windows-platform-test-if-a-file-is-fully-flushed-to-disk/165828>\
**Category:** Ruby\
**Created:** [April 17, 2009, 10:32pm UTC](https://www.ruby-forum.com/t/windows-platform-test-if-a-file-is-fully-flushed-to-disk/165828 "2009-04-17T22:32:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianwisti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/fbc32d/32.png) [@brianwisti](https://www.ruby-forum.com/u/brianwisti)\
**Post date:** [April 17, 2009, 10:32pm UTC](https://www.ruby-forum.com/t/windows-platform-test-if-a-file-is-fully-flushed-to-disk/165828/1 "2009-04-17T22:32:38Z")

</div>

Hi all,

I’ve written a Ruby script that scans a directory for new files at a  
specified interval, using Directory\_Watcher (Thanks for the great gem  
Tim  
Pease!), and when a new file is added to the directory - it streams it  
off  
to my Web Application.

The problem I’m having is with large files that take a long time to copy  
into a folder in Windows, the file is added and picked up immediately  
… So  
the application tries to begin streaming, but ends up getting a  
“Errno::EACCES: Permission denied” on the file because it is still being  
copied.

I’ve been trying to find a way to test a file in windows to see if it is  
readable/writable? I’ve tried all of the usual ruby methods:

File.size = reports the total size of the file, even if its still  
copying  
File.readable? ==\> always returns true even during the copy  
File.writeable? ==\> always returns true even during the copy.

So I guess my question is: Does anyone know how to test if a file is  
complete in Windows?

Thanks,

Brian

---

<div class="post-metadata">

**Author:** ![brianwisti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/fbc32d/32.png) [@brianwisti](https://www.ruby-forum.com/u/brianwisti)\
**Post date:** [April 17, 2009, 10:36pm UTC](https://www.ruby-forum.com/t/windows-platform-test-if-a-file-is-fully-flushed-to-disk/165828/2 "2009-04-17T22:36:44Z")

</div>

On Apr 17, 2009, at 13:32, Brian W. wrote:

> it is  
> readable/writable? I’ve tried all of the usual ruby methods:
> 
> File.size = reports the total size of the file, even if its still  
> copying  
> File.readable? ==\> always returns true even during the copy  
> File.writeable? ==\> always returns true even during the copy.
> 
> So I guess my question is: Does anyone know how to test if a file is  
> complete in Windows?

Why not rescue Errno::EACCESS and retry at a later time?

---

<div class="post-metadata">

**Author:** ![brianwisti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/fbc32d/32.png) [@brianwisti](https://www.ruby-forum.com/u/brianwisti)\
**Post date:** [April 17, 2009, 11:53pm UTC](https://www.ruby-forum.com/t/windows-platform-test-if-a-file-is-fully-flushed-to-disk/165828/3 "2009-04-17T23:53:26Z")

</div>

Thanks for replying Eric…

Obviously I’m fairly inexperienced and didnt even think that 🙂 I guess  
I’ll  
have to focus on learning the proper ways to use rescue / retry.
