Check directory is full or not?
Show older comments
How we can check the directory is full or not before write data to the file in that directory?
2 Comments
KSSV
on 21 Oct 2016
s = dir(path) ;
Gives you the contents of the directory. What do you mean by full?
Accepted Answer
More Answers (2)
function [x] = dirsize(path)
s = dir(path);
name = {s.name};
isdir = [s.isdir] & ~strcmp(name,'.') & ~strcmp(name,'..');
subfolder = fullfile(path, name(isdir));
x = sum([s(~isdir).bytes cellfun(@dirsize, subfolder)]);
end
Gives you the size of input directory in bytes....you can convert bytes to MB by dividing with 10^6.
rooz
on 5 Feb 2020
0 votes
Hi,
Just a question, wouldn't the following work as well:
if numel(dir(path)) <=2
% folder is empty
else
% folder isn't empty
end
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!