Skip to main content
Known Participant
August 24, 2013
Answered

Determine if a file is open or in use or writable

  • August 24, 2013
  • 1 reply
  • 811 views

Is there a way to determine if a file is currently open in another application?

Possibly by seeing if it is writable or by some other means?

I do not want to write to it if it is available to write. I just thought maybe that was a way to detrmine if it is in use.

The reason I want to do this:

I run a timer in an AIR app and if the size of a file opened in another app has changed since the time the file was opened ( from within AIR ) then it alerts the user.

However, if the User does not change the File, the timer nevers knows when to turn off.

If there is no way way to determine if a file is open, then I would take other suggestions for this method.

This topic has been closed for replies.
Correct answer Aaron Beall

I've faced a similar challenge. This was my solution:

1. Poll the file for changes (as3corelib has FileMonitor that does this) and if there's a change, notify the user and resolve merge/conflict as necessary

2. At the time of writing, if the file cannot be written to then FileStream/open() will throw an error and you can notify the user and resolve the problem

You could also poll for file-lock by periodically calling FileStream/open() and immediately closing, but that's probably not a good idea. Dealing with the problem when the client tries to write to the file seems like the best way to go.

-Aaron

1 reply

Aaron BeallCorrect answer
Inspiring
August 26, 2013

I've faced a similar challenge. This was my solution:

1. Poll the file for changes (as3corelib has FileMonitor that does this) and if there's a change, notify the user and resolve merge/conflict as necessary

2. At the time of writing, if the file cannot be written to then FileStream/open() will throw an error and you can notify the user and resolve the problem

You could also poll for file-lock by periodically calling FileStream/open() and immediately closing, but that's probably not a good idea. Dealing with the problem when the client tries to write to the file seems like the best way to go.

-Aaron

DachFlachAuthor
Known Participant
August 29, 2013

Thank you Aaron.

I will give this is a try - sounds good.