File test

A

Adrian

Hi,
Before I open a file to read it etc how can I test to ensure it not
currently in use by another process?

the scenario is that I'm watch for a file to be created once it is I read
its contents and depending what they are I move it! however I'm getting
error when I'm am reading the file before its is fully written ( the writing
is slow as its over a WAN!) so I want to loop until the file is fully
created/ written.

thanks
 
A

Armin Zingler

Adrian said:
Hi,
Before I open a file to read it etc how can I test to ensure it
not currently in use by another process?

No. If it was possible, it wouldn't make sense, because, between checking it
and, if finding out it is not in use anymore, and opening it, the file could
be opened again by another process.
the scenario is that I'm watch for a file to be created once it is I
read its contents and depending what they are I move it! however I'm
getting error when I'm am reading the file before its is fully
written ( the writing is slow as its over a WAN!) so I want to loop
until the file is fully created/ written.


Armin
 
G

Gman

If you have control over the application creating the file, have it
create it with a different filename while its writing and then, once
complete, rename it.

Otherwise you can trap the error and postpone your read/move.

HTH
 
A

Adrian

Hi
thanks, this is what i have done i.e. do while, catch, open file...

I thought I was missing a better approach!

I also have an error counter and a sleep in the loop so as not to wait for
ever and a day!

Thanks
 

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