MATLAB Answers

How can I check if a HDF5 file is already in use?

4 views (last 30 days)
Anne Tye
Anne Tye on 28 Sep 2020
Commented: Mario Malic on 28 Sep 2020
Madam, Sir,
I use the following functions to feed a h5 file :
h5create.m / h5write.m /h5writeatt.m
When writing in it while the file is used by another interface, it gets corrupted and unusable.
Is there a way to check if the file is in use and even close it, in order to write in it again without corrupting it?
Thanks in advance for any feedback and best regards,
Anne Tye

  1 Comment

Mario Malic
Mario Malic on 28 Sep 2020
  • There is a function called fileattrib, but in my case (Windows), it didn't work properly the last time I worked with it.
  • Also, you can try with fopen, when the file is in use, check what is returned when you call the function.
From the documentation
fileID = fopen(filename) opens the file, filename, for binary read access, and returns an integer file identifier equal to or greater than 3. MATLAB® reserves file identifiers 0, 1, and 2 for standard input, standard output (the screen), and standard error, respectively.
If fopen cannot open the file, then fileID is -1.
  • If this interface is some sort of program/process, you can check here

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by