フィルターのクリア

Is there a way to detect if a file is open in another application from MATLAB?

85 ビュー (過去 30 日間)
quai20
quai20 2011 年 2 月 8 日
I have a problem reading a file and I would like to check if the file is already opened by another application before using load.
I have received access conflicts when I try to read a file with MATLAB while this file is written to by another application.
Any idea?
  2 件のコメント
Walter Roberson
Walter Roberson 2011 年 2 月 8 日
Are you willing to restrict this question to MS Windows and access to either local drives or a shared drive on a Windows server? The answers get much more complicated in other cases.
quai20
quai20 2011 年 2 月 8 日
Yes everything is on the local drive in my case.

サインインしてコメントする。

採用された回答

Andreas Goser
Andreas Goser 2011 年 2 月 8 日
The FOPEN command returns a -1 if there is an issue with opening the file. You can use that. Even if you use LOAD or other functions to really import the data, you can use FOPEN (and probably FCLOSE) to test if it is blocked by another application.
  3 件のコメント
quai20
quai20 2011 年 2 月 8 日
it seems to work but only when the other application is writing and in the meantime i want to read (I get the fid=-1). But if it's not writing (but the file is open), I still can open it with my application so I don't know if my file is already open...:(
Andreas Goser
Andreas Goser 2011 年 2 月 8 日
If the other application is not writing, there is no "block". So a question here is what else do you have under control and how narrow the problem is.

サインインしてコメントする。

その他の回答 (1 件)

Aurelien Queffurust
Aurelien Queffurust 2011 年 2 月 8 日
Another strategy is to use a file as a semaphore.
This trick is used for example in this submission: Multicore - Parallel processing on multiple cores

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by