Created
July 18, 2020 05:38
-
-
Save adriaanbd/c203d182d22726b28a00c6066f7267fc to your computer and use it in GitHub Desktop.
Gets a list of of paths of all pdf files under target directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
def get_pdfs(path: str) -> list: | |
"""Returns a list of paths of all pdf files under a target directory.""" | |
assert isinstance(path, str), 'Path must be a string' | |
path_obj = Path(path) | |
assert path_obj.is_dir(), 'Path must be an existing directory' | |
path_iter = path_obj.rglob('*.pdf') | |
file_list = [str(f) for f in path_iter if f.is_file()] | |
return file_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use like: