Check free disk space from Matlab/Octave

Matlab function that checks free disk space: diskfree.m. For a long-running program, helps avoid totally filling a hard drive.

Assumes you have one-time setup Matlab-Python connection

function freebytes = diskfree(mydir)
%% returns disk free space in bytes
% example:  diskfree('~')

validateattributes(mydir, {'char'}, {'scalartext'}, mfilename, 'drive letter to get free space from', 1)

freebytes = int64(py.shutil.disk_usage(py.pathlib.Path(mydir).expanduser().resolve()).free);

end