所有子文件夹中图片个数matlab代码实现

clc
clear all
close all

%% 查看子文件下有多少张图片

maindir='G:CASIA-maxpy-clean';
subdir = dir( maindir ); % 先确定子文件夹
N=0;
lensubdir=length(subdir);
fprintf('一共有%d个子文件夹',lensubdir-2) ; %去除两个符号文件
for i = 1 : lensubdir
%从第三个开始
if( isequal( subdir( i ).name, '.' ) || ...
isequal( subdir( i ).name, '..' ) || ...
~subdir( i ).isdir ) % 如果不是目录跳过
continue;
end
fprintf('第%d个子文件夹 ',i);
subdirpath = fullfile( maindir, subdir( i ).name, '*.jpg' );
images = dir( subdirpath ); % 在这个子文件夹下找后缀为jpg的文件
N=N+length(images);
% % 遍历每张图片
% for j = 1 : length( images )
% imagepath = fullfile( maindir, subdir( i ).name, images( j ).name )
% % imgdata = imread( imagepath ); % 这里进行你的读取操作
% end
end
fprintf('共有%d个图片',N);

原文地址:https://www.cnblogs.com/LiuSY/p/7148877.html