1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-17 19:21:04 +00:00

lib: Add readTree function to filesystem

Add a friendly function to easily return a flattened list of files
within a directory.

This is useful if you want to easily iterate or concatSep the list of
files all found within a directory.
(i.e. when constructing Java's CLASSPATH)

Style improvements

Co-authored-by: Silvan Mosberger <github@infinisil.com>
This commit is contained in:
Farid Zakaria 2020-10-19 14:33:52 -07:00
parent 8b4d70ca94
commit 5f1d1bc57e

View file

@ -42,4 +42,16 @@
type = (builtins.readDir parent).${base} or null;
in file == /. || type == "directory";
in go (if isDir then file else parent);
# listFilesRecursive: Path -> [ Path ]
#
# Given a directory, return a flattened list of all files within it recursively.
listFilesRecursive = dir: lib.flatten (lib.mapAttrsToList (name: type:
if type == "directory" then
lib.filesystem.listFilesRecursive (dir + "/${name}")
else
dir + "/${name}"
) (builtins.readDir dir));
}