I want to have a list of all full sub-folders. The list shall not contain any parent folder.
I get the list of dirs using
dirs = regexp(genpath(basePath),['[^;]*'],'match');
However that functions is really slow. Probably because my folders contain thousands of files.
The removefall of the parent folders is done this way: Is there a possibility to optimize this in terms of code size and speed?
function [ ListOfDirs ] = findsubfolders( basePath )
dirs = regexp(genpath(basePath),['[^;]*'],'match');
index = 0;
for k = 1:numel(dirs)
currFolder = dirs{k};
if numel(strrep(currFolder, basePath,'')) ~= 0
if isempty(strfind(currFolder, 'remove'))
index = index + 1;
selectedDirs{index} = currFolder;
end
end
end
dirs = selectedDirs;
idx = 0;
for k = 1:numel(dirs)
currFolder = dirs{k};
isNotParentFolder = false;
for s = 1:numel(dirs)
if s ~= k
compFolder = dirs{s};
if numel(strrep(strrep(currFolder, compFolder,''),currFolder,'')) ~= 0
isNotParentFolder = true;
end
end
if isNotParentFolder
idx = idx + 1;
ListOfDirs{idx} = currFolder;
break;
end
end
end
end