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

B

Brian Wallace

[Note: parts of this message were removed to make it a legal post.]

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
 
E

Eric Hodel

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?

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

Brian Wallace

[Note: parts of this message were removed to make it a legal post.]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top