What is the best way to figure out the size of a file using MATLAB? The first thought that comes to mind is size(fread(fid)).
A:
Use the fact that MatLab has access to Java Objects:
myFile = java.io.File('filename_here')
flen = length(myFile)
KitsuneYMG
2009-05-11 19:55:42
+10
A:
You can use the DIR function to get directory information, which includes the sizes of the files in that directory. For example:
dirInfo = dir(dirName); % Where dirName is the directory name where the
% file is located
index = strcmp({dirInfo.name},fileName); % Where fileName is the name of
% the file.
fileSize = dirInfo(index).bytes; % The size of the file, in bytes
Or, since you are looking for only one file, you can do what Elazar said and just pass an absolute or relative path to your file to DIR:
fileInfo = dir('I:\kpe\matlab\temp.m');
fileSize = fileInfo.bytes;
gnovice
2009-05-11 19:55:51
Hey, you earned a badge because of my answer (8>3*2). ;-)
Elazar Leibovich
2009-05-13 03:51:03
Unfortunately, no. Your answer would have to have at least 10 upvotes, which means mine would have to have 20. I don't think there are enough people on SO who are interested in MATLAB for those sorts of numbers to happen. We can dream though... =)
gnovice
2009-05-13 04:19:20
+9
A:
Please see the dir function as stated above.
Please note that the dir function works on files and not on directories only.
>> s = dir('c:\try.c')
s =
name: 'try.c'
date: '01-Feb-2008 10:45:43'
bytes: 20
isdir: 0
datenum: 7.3344e+005
Elazar Leibovich
2009-05-11 20:08:57