confirm valid file identifier before flcose?
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am using GUI callbacks to close a file. Sometimes the file is aready closed, and I get an invalid file identifier error. Is there a robust way to check if the file is still open before calling fclose? I have tried using fopen('all') but that does not always catch it.
0 commentaires
Réponse acceptée
Les Beckham
le 1 Fév 2024
If you call fopen on the file identifier when the file is closed it will return empty (instead of returning the filename). So, you can do this:
if ~isempty(fopen(fid))
fclose(fid);
end
0 commentaires
Plus de réponses (2)
Voir également
Catégories
En savoir plus sur Software Development Tools dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!