Is there a way to detect if a file is open in another application from MATLAB?
56 次查看(过去 30 天)
显示 更早的评论
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
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.
采纳的回答
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 个评论
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
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!