How do I find the size of a file on disk from MATLAB?

83 views (last 30 days)

Accepted Answer

MathWorks Support Team
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.)

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Tags

No tags entered yet.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!