Detecting if a file is open

gOS bkirklin at quantapoint.com
Fri May 30 14:53:34 CDT 2008


I'm wondering if there is a better way to do this.

fid = fopen('testfile.txt','w')

if(exist('fid'))
   if(isequal(ferror(fid),''))
     fclose(fid);
   end
end

essenially, I'm assuming that if ferror is an empty string, then the file
needs closed. I'm using try catch error handling, and just want to make sure
everything is cleaned up properly before I exit the specific function. This
is useful when you want to work with a file without having to completely
shut down octave and restart it.

Is there a method that is more often used to tell if a file is open? Perhaps
more reliably? I just played around until I found this.
-- 
View this message in context: http://www.nabble.com/Detecting-if-a-file-is-open-tp17566839p17566839.html
Sent from the Octave - General mailing list archive at Nabble.com.



More information about the Help-octave mailing list