Check directory is full or not?
Afficher commentaires plus anciens
How we can check the directory is full or not before write data to the file in that directory?
2 commentaires
KSSV
le 21 Oct 2016
s = dir(path) ;
Gives you the contents of the directory. What do you mean by full?
Réponse acceptée
Plus de réponses (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
le 5 Fév 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
Catégories
En savoir plus sur Search Path dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!