function [datapath, label, classinfo] = getdatapath(datadir, type)
% generate the image paths and the corresponding labels

% subdirectory
label = [];
% find subdirectory

if nargin < 2
subdir = dir(datadir);
it = 0;
for i = 3:length(subdir)
    datasubdir{i-2} = [datadir subdir(i).name];
    dataname = dir(datasubdir{i-2});
    % generate labels
    label = [label (i-2)*ones(1,size(dataname,1)-2)];
    % save class information
    classinfo{i-2} = subdir(i).name;
    for j = 3:size(dataname,1)
        it = it + 1;
	% generate image paths
	datapath{1,it} = [datasubdir{i-2} '/' dataname(j).name];
    end
end
else
subdir = dir(datadir);
it = 0;
for i = 3:length(subdir)
    datasubdir{i-2} = [datadir subdir(i).name];
    dataname = dir([datasubdir{i-2} '/*' type]);
    % generate labels
    label = [label (i)*ones(1,size(dataname,1)-2)];
    % save class information
    classinfo{i} = subdir(i).name;
    for j = 1:size(dataname,1)
        it = it + 1;
        % generate image paths
        datapath{1,it} = [datasubdir{i-2} '/' dataname(j).name];
    end
end
end

