diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-04-05 17:45:25 +0200 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-04-05 17:45:25 +0200 |
commit | aefd0cb4fa1a949beabc51e88a5c46843043a439 (patch) | |
tree | e978249655fcab58f9ee1479c268ca8b06af7e8d /bsie/utils/filewalker.py | |
parent | 0b6b1d27756d1c02a2a667ebfc1a119081ff079f (diff) | |
download | bsie-aefd0cb4fa1a949beabc51e88a5c46843043a439.tar.gz bsie-aefd0cb4fa1a949beabc51e88a5c46843043a439.tar.bz2 bsie-aefd0cb4fa1a949beabc51e88a5c46843043a439.zip |
move file walker into its own module
Diffstat (limited to 'bsie/utils/filewalker.py')
-rw-r--r-- | bsie/utils/filewalker.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bsie/utils/filewalker.py b/bsie/utils/filewalker.py new file mode 100644 index 0000000..3c36926 --- /dev/null +++ b/bsie/utils/filewalker.py @@ -0,0 +1,31 @@ + +# standard imports +import os +import typing + +# exports +__all__: typing.Sequence[str] = ( + 'list_files', + ) + + +## code ## + +def list_files( + roots: typing.Iterable[str], + recursive: bool = True, + follow_symlinks: bool = True, + ) -> typing.Iterator[str]: + """Iterate over all files in *roots*, recursively by default.""" + # index input paths + for path in roots: + if not os.path.exists(path): + continue + elif os.path.isdir(path) and recursive: + for dirpath, _, filenames in os.walk(path, topdown=True, followlinks=follow_symlinks): + for filename in filenames: + yield os.path.join(dirpath, filename) + elif os.path.isfile(path): + yield path + +## EOF ## |