DECROMAX

Return list of all files within dir with specified filetype

Mar 7th, 2022
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.29 KB | None | 0 0
  1. from pathlib import Path
  2.  
  3. def all_file_type(dir_path: str, file_ext: str) -> list:
  4.     """Returns  list of all files within dir with specified filetype
  5.    arg 1 dir path, arg 2 : file ext"""
  6.     str_path = Path(dir_path).glob(f"*{file_ext}")
  7.     files = [i for i in str_path]
  8.     return files
Advertisement
Add Comment
Please, Sign In to add comment