Simple question: I am opening a file in matlab 7.x, and I want to test if it is empty before reading it. What's the best way to do this?
s = dir('c:\somefile. txt'); if s. bytes == 0 % empty file else % open the file and read it end; I assumed by empty that you meant that there is really nothing in the file including new line characters.
Description. result = isfolder( folderName ) returns 1 if folderName is a folder located on the specified path or in the current folder. Otherwise, isfolder returns 0.
Accepted Answer filePattern = fullfile('./', '*. m'); files = dir(filePattern);
Taking some knowledge from this previous question, I would do the following
s = dir('c:\somefile.txt');
if s.bytes == 0
% empty file
else
% open the file and read it
end;
I assumed by empty that you meant that there is really nothing in the file including new line characters. If by empty you mean only new line characters, then you should go ahead with your solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With