Filenames beginning with a dot are not suppressed by default, but the directories "." and ".." are omitted from SubdirList.
Success: [eclipse]: read_directory("/usr/john", "*", Dirlist, Filelist). Dirlist = ["subdir1", "subdir2"] Filelist = ["one.c", "two.c", "three.pl", "four.pl"] yes. [eclipse]: read_directory(., "[^t]*.pl", Dirlist, Filelist). Dirlist = ["subdir1", "subdir2"] Filelist = ["four.pl"] yes. Fail: [eclipse]: read_directory(".", "*.c", _, ["one.c"]). no. Error: read_directory(_, "*", Dirs, Files). (error 4) read_directory([46], "*", Dirs, Files). (error 5) read_directory(".", _, Dirs, Files). (error 4) read_directory(".", 3, Dirs, Files). (error 5) read_directory(".", "*.pl", Dirs, file). (error 5) read_directory("/private", "*", _, Files). (error 170) % EXAMPLE: find_tree(+Root, +Pattern, -ListOfRelativeFiles) % Recursively find all files matching Pattern below the directory % or list of directories Roots. find_tree(Root, Pattern, AllFiles) :- (atom(Root);string(Root)), !, find_dir(Root, "", "", Pattern, AllFiles, []). find_tree(Roots, Pattern, AllFiles) :- find_tree(Roots, Pattern, AllFiles, []). find_tree([], _Pattern, AllFiles, AllFiles). find_tree([Root|Roots], Pattern, AllFiles, AllFiles0) :- find_dir(Root, "", "", Pattern, AllFiles, AllFiles1), find_tree(Roots, Pattern, AllFiles1, AllFiles0). find_dir(_, _, [], _, AllFiles, AllFiles) :- !. find_dir(Root, RelPath, [Dir|Dirs], Pattern, AllFiles, AllFiles0) :- !, find_dir(Root, RelPath, Dir, Pattern, AllFiles, AllFiles1), find_dir(Root, RelPath, Dirs, Pattern, AllFiles1, AllFiles0). find_dir(Root, RelPath, Dir, Pattern, AllFiles, AllFiles0) :- ( RelPath=="" -> RelDir=Dir ; concat_string([RelPath,/,Dir], RelDir) ), ( RelDir=="" -> AbsDir=Root ; concat_string([Root,/,RelDir], AbsDir) ), read_directory(AbsDir, Pattern, SubDirs, Files), find_files(Root, RelDir, Files, AllFiles, AllFiles1), find_dir(Root, RelDir, SubDirs, Pattern, AllFiles1, AllFiles0). find_files(_, _, [], AbsFiles, AbsFiles). find_files(Root, RelDir, [File|Files], [AbsFile|AbsFiles], AbsFiles0) :- ( RelDir=="" -> concat_string([Root,/,File], AbsFile) ; concat_string([Root,/,RelDir,/,File], AbsFile) ), find_files(Root, RelDir, Files, AbsFiles, AbsFiles0).