Home All Groups Group Topic Archive Search About
Author
2 Mar 2006 3:42 PM
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

Author
2 Mar 2006 8:00 PM
Armin Zingler
"Adrian" <Adrian@nospamhotmail.com.uk> schrieb
> 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
Author
2 Mar 2006 11:12 PM
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

Adrian wrote:
Show quoteHide quote
> 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
>
>
>
Author
2 Mar 2006 11:39 PM
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

Show quoteHide quote
"Gman" <nah> wrote in message news:uOQE55kPGHA.1088@tk2msftngp13.phx.gbl...
> 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
>
> Adrian wrote:
>> 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
>>
>>