Based on this answer, I'm trying to find all directories and subdirectories that contain a specified string. Right now I've the following code, which show ALL directories and subdirectories (the string pattern is not implemented and that's what I would like to have):
function fileNames = findAllDirectories(directory, wildcardPattern)
import org.apache.commons.io.filefilter.*;
import org.apache.commons.io.FileUtils;
import java.io.File;
files = FileUtils.listFilesAndDirs( File(directory),...
NotFileFilter(TrueFileFilter.INSTANCE),...
DirectoryFileFilter.DIRECTORY);
fileNames = cellfun(@(f) char(f.getCanonicalPath()),...
cell(files.toArray()),...
'uniformOutput', false);
end
How do I specify to search for a name pattern in the directory/subdirectory names?
For example, if I have the following directory structure:
C:\aaa
C:\aaa\aaa
C:\aaa\bbb
C:\aaa\ccc
C:\aaa\bbb\ccc
C:\aaa\ddd
C:\aaa\ddd\bbb
and that I call findAllDirectories('C:\aaa','ccc')
, the result should be :
C:\aaa\ccc
C:\aaa\bbb\ccc