How do I find the size of a file on disk from MATLAB?
83 views (last 30 days)
Show older comments
I would like to find the size of a file on disk from MATLAB.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
There are two ways to have your program determine the size of a file:
%-- METHOD #1 --
s = dir('myfile.dat');
filesize = s.bytes
%-- METHOD #2 --
fid = fopen('myfile.dat');
fseek(fid, 0, 'eof');
filesize = ftell(fid)
fclose(fid);
The dir function also returns the filename (s.name), last modification date (s.date), and whether or not it is a directory (s.isdir). (The second method requires read access to the file.)
0 Comments
More Answers (0)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!