The files below the folder path, as full paths: path joined with each name with /. Directories are not listed;
links to files and links with a missing target are. With recursive it also lists the files of every sub-folder.
follow_directory_symlinks is as in visit_files.
file_list :: (
path: string,
recursive := false,
follow_directory_symlinks := true
) -> [] string
The order is the file system's. The array and every string in it are new allocations from context.allocator: free each
string and then the array. A missing folder or a read error is logged, and the files found before it are still returned.
Parameters
- path: string
- recursive := false
- follow_directory_symlinks := true
Returns
- [] string
#import "Extensions/Environment";
#import "File";
base := environment_variable("TMPDIR");
if base == "" base = environment_variable("TEMP");
if base == "" base = "/tmp";
root := tprint("%/jai-doc-file-list", base);
defer {
file_delete(tprint("%/a.txt", root));
file_delete(tprint("%/sub/b.txt", root));
delete_directory(tprint("%/sub", root));
delete_directory(root);
}
assert(make_directory_if_it_does_not_exist(tprint("%/sub", root), recursive = true));
assert(write_entire_file(tprint("%/a.txt", root), "a"));
assert(write_entire_file(tprint("%/sub/b.txt", root), "b"));
top := file_list(root);
assert(top.count == 1);
for name: top free(name);
array_free(top);
all := file_list(root, recursive = true);
assert(all.count == 2);
for name: all free(name);
array_free(all);