File Exchange

image thumbnail

Disk usage

version (1.99 KB) by Igor
Queries free and total space of a volume


Updated 28 May 2013

View Version History

View License

%DISK_FREE return free disk space for specified folder in bytes (double)
% * some_path - string, existing file or folder path. Should be global.
% * disk_free('C:\temp'); % regular usage
% * disk_free('C:\temp\1.txt'); % path points to a file
% * disk_free('\\?\C:\temp'); % UNCW path
% * disk_free('\\\\C:\temp'); % UNCW path with with java-style prefix
% * disk_free('\\IMP\Ctemp'); % samba share folder
% *
% * disk_free('\\IMP'); % samba share root. Results in error.
% * disk_free('C'); % Use 'C:' instead. Results in error.
% * disk_free('disk_free') % Matlab function. Results in [0 0 0]
% % or some other result, if corresponding
% % local file was found.
% % i.e. don't use local paths!
% Would result in an error for an empty DVD-rom drive (disk not inserted).
% And similar cases.

Cite As

Igor (2021). Disk usage (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)

Younes Zerouali

Useful, thanks!

Rob Campbell

Useful. Why not correct the invalid usage cases where possible instead of listing them? e.g. if the user enters 'C' you can silently convert it to 'C:'

David Freedman


Thanks for your review, Jan!
I've tired to fix those defects you've described. Just uploaded it. Hope it would be updated shortly.


Just a note: "\\?\C:\" is not an UNC path, but this is the prefix allows to use Windows API functions with long names (uo to about 32767). "\\Server\share\" is an UNC path and you can use it to access samba shares, but not only them.

"path" is an important Matlab function. Shadowing it by a local variable with the same name can lead to serious troubles e.g. during debugging.

Beside these small details, this function is well documented, useful and usable. I'd add the name of the author and a version date to the help section.



This submission is based on Jan Simon's suggestion:

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Disk Usage, diskfree

Inspired: BiofilmQ

Community Treasure Hunt

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

Start Hunting!