how can i check if the file.mat is in use with another application ?

5 views (last 30 days)
i am using files called 'try_000.mat' and 'try_000.txt' to save some data, but before loading the files i want to check using matlab script if these files are in use with another software or not,

Answers (1)

Image Analyst
Image Analyst on 12 Jul 2014
Other than MATLAB, what other software would be using them?
I rarely find txt files locked but you can always try to open it with fopen() and if you get -1 then perhaps some other files has locked it, or you don't have permission to open it for some other reason.
  2 Comments
wael taie
wael taie on 12 Jul 2014
i do not want to open it , i want first check if it is in use with another matlab on the same computer or not , i am using two matlab platform to do two separate processes but there are a common mat and txt files between the two processes. so, firstly i want to check if the file in use or not before dealing with it
Image Analyst
Image Analyst on 12 Jul 2014
You only open instantaneously to see if it's locked, then you close it immediately. Anyway, your other MATLAB process won't lock the text file, especially since it's not even opening it. The .mat file is opened just for a fraction of a second while it's pulling stuff out of it with the load() function.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!