Determine when a file is ready

S

sbparsons

I need to write an app that picks up images from a folder and does some work
on them (resize, compress etc). The folder in which the images reside has a
FileSystemWatcher triggering events when files are dropped in.

I need to be able to determine when the file is ready to be accessed by my
app, as some of the files may be large and the copy procedure may take some
time (in the order of seconds). I have the LastWrite filter set on my FSW but
that raises the changed event - which is also raised at other (seemingly
random) times - and there is no info in the event raised that it is the
LastWrite stage of the action.

Is there any exact way of determining when the file is available? This is
through a windows service so can't use the Win32 SHFileOperation api call...
(and a 'try - catch' solution isn't ideal)
 
S

sbparsons

Thanks Nicholas - sorry, I should have searched on a few more keywords.

Nicholas Paldino said:
A similar question was posted a few days ago, with the following
replies:

http://groups.google.com/group/micr...stemwatcher+nicholas+paldino#496e3132135ea3c6


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

sbparsons said:
I need to write an app that picks up images from a folder and does some
work
on them (resize, compress etc). The folder in which the images reside has
a
FileSystemWatcher triggering events when files are dropped in.

I need to be able to determine when the file is ready to be accessed by my
app, as some of the files may be large and the copy procedure may take
some
time (in the order of seconds). I have the LastWrite filter set on my FSW
but
that raises the changed event - which is also raised at other (seemingly
random) times - and there is no info in the event raised that it is the
LastWrite stage of the action.

Is there any exact way of determining when the file is available? This is
through a windows service so can't use the Win32 SHFileOperation api
call...
(and a 'try - catch' solution isn't ideal)
 
S

Scott Roberts

A batch file interface that I worked on several years ago used file
extensions instead of the file "marker" idea. The client would write files
into the directory with a "*.wrk" extension then rename them to the
appropriate extension once the file has been completely written. The server
would ignore "*.wrk" files and was free to process all other files. I
believe that the "rename" function does not actually open the file and so
sharing violations are not possible.

As Nicholas said, if you can't control the client process you're kinda stuck
with try...catch.


Nicholas Paldino said:
A similar question was posted a few days ago, with the following
replies:

http://groups.google.com/group/micr...stemwatcher+nicholas+paldino#496e3132135ea3c6


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

sbparsons said:
I need to write an app that picks up images from a folder and does some
work
on them (resize, compress etc). The folder in which the images reside has
a
FileSystemWatcher triggering events when files are dropped in.

I need to be able to determine when the file is ready to be accessed by
my
app, as some of the files may be large and the copy procedure may take
some
time (in the order of seconds). I have the LastWrite filter set on my FSW
but
that raises the changed event - which is also raised at other (seemingly
random) times - and there is no info in the event raised that it is the
LastWrite stage of the action.

Is there any exact way of determining when the file is available? This is
through a windows service so can't use the Win32 SHFileOperation api
call...
(and a 'try - catch' solution isn't ideal)
 

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

Top