Sum file and Directory
Hello, meet again with me, this time I will discuss the issue of the number of directories and files, to determine the number of files and directories using function following:
%parameter of functios using user input
function getSumfileDirectory(directory)
listDir=cellstr(ls(directory));%get list file and directory
dir=0; %initialization sum dir an file
file=0;
for i=3:length(listDir(:,1))
if exist([directory,'\',char(listDir(i))],'dir')==7 %cheking directory
dir=dir+1;
else %cheking file
file=file+1;
end
end
%displaying directory
disp(['sum of directory : ',num2str(dir)]);
disp(['sum of file : ',num2str(file)]);
Example execute getSumfileDirectory
![]() |
| Fig. 1 Example execute fungtions |
