confirm valid file identifier before flcose?
8 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Les Beckham
2024 年 2 月 1 日
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 件のコメント
その他の回答 (2 件)
参考
カテゴリ
Help Center および File Exchange で Software Development Tools についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!