Is there any function in MATLAB that determine free disk space? I have made a temporal function that uses MS-DOS dir
command and parses the last line of its output. I think it's working as expected but I guess (1) it won't work in other systems (OS X, Linux, Unix, etx.) and (2) can also fail in different Windows versions. Perhaps someone could improve it to make it more generic? Thanks
The code:
function out = freediskspace
[~,d] = dos('dir');
C = textscan(d,'%s','Delimiter','\n'); C = C{1}{end};
C = strrep(C,',','');
r = regexp(C,'\d+','match');
out = str2double(r{2});
end
Accepted Answer disk: 2 GB for MATLAB only, 4–6 GB for a typical installation. memory: 2 GB, or 4 GB if you use Simulink.
You can use genpath to make a list of all folders, then use dir() to see if the file you want is in that folder.
MATLAB is a paid software and it get regular updates, On the other hand Octave is an open source programming language. Therefore it doesn't get the regular updates and has limited features as compared with MATLAB. That's why MATLAB is 10 GB is size and Octave is only 300 MB.
You can use a Java call (this works on both Linux and Windows - I have not checked OSX but it should be fine).
function free = getFreeSpace(path)
if nargin < 1 || isempty(path)
path= '.';
end
free = java.io.File(path).getFreeSpace();
end
For example,
>> f = getFreeSpace('C:\')
f =
3.9338e+11
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