To debug
location = 'C:/Users/donal/Desktop/ImageDatasets/DATASET 1/*.jpg';
pieces = strsplit(location, '/');
numpieces = length(pieces);
last_valid = 0;
for K = 1 : numpieces
sofar = fullfile(pieces{1:K});
dinfo = dir(sofar);
if isempty(dinfo); break; end
last_valid = K;
end
if last_valid == 0
fprintf('NOTHING in the path was found, not even the hard disk!\n');
else
fprintf('found up to "%s"\n', sofar);
if last_valid == numpieces
fprintf('which is the entire path\n');
else
fprintf('but not "%s"\n', pieces{last_valid+1});
end
end