从主文件中读取n个子文件夹中的图片(每一子文件中有两个文件夹,每两个文件中有18张图片)

时间:2021-01-29 21:37:42
tic
clc;
clear all;
close all;
str = 'F:\shijie-test\test-finger\';
pt = dir(str);
foldname = [];
k = 0;
for i = 1 : length(pt)
    ifstrcmp(pt(i).name, '.') | strcmp(pt(i).name, '..')
        continue;
    else
        k = k + 1;
        foldname{k} = pt(i).name;
    end
end
for i = 1:length(foldname)
    temp = strcat(str, foldname{i}, '\');
    temp1 = dir(temp);
    k = 0;
    for j = 1:length(temp1)
        ifstrcmp(temp1(j).name, '.') | strcmp(temp1(j).name, '..')
            continue;
        else
            k = k + 1;
            foldname1{i, k} = temp1(j).name;
            foldname1{i, k} = strcat(temp, foldname1{i, k}, '\');
        end
    end
end
 [m, n] = size(foldname1);
for i = 1:m
    for j = 1:2
        temp = strcat(foldname1{i, j}, '*.bmp');
        temp1 = dir(temp);
        for k = 1:length(temp1)
            if 1 == j
                jpgpath{i, k} = strcat(foldname1{i, j},  temp1(k).name);
            end
            if 2 == j
                jpgpath{i, 18 + k} = strcat( foldname1{i, j}, temp1(k).name);
            end    
        end
    end
end
celldisp(jpgpath);
toc