a simple package to get all files with given file extension in a directory
Project description
READ ME
This is a very simple package which is basically a wrapper around glob; it simply gets all the files with extension matching a list of extensions in a given directory. I found that I was including functionality like this in so many other projects I might as well just make it a package. Plus I wanted to play with poetry.
install
pip install get_all_files
Examples
get all jpg files in home directory
from get_all_files import get_all_files
from pathlib import Path
home_dir = Path('~').expanduser()
jpg_files = get_all_files(home_dir, 'jpg')
get all jpg AND png files in home directory
from get_all_files import get_all_files
from pathlib import Path
home_dir = Path('~').expanduser()
jpg_files = get_all_files(home_dir, ['jpg', 'png'])
get all jpg files starting with 'a' in home directory
from get_all_files import get_all_files
from pathlib import Path
home_dir = Path('~').expanduser()
jpg_files = get_all_files(home_dir, 'jpg', file_name='a*')
get absolute file paths instead of file names
from get_all_files import get_all_files
from pathlib import Path
home_dir = Path('~').expanduser()
jpg_files = get_all_files(home_dir, ['jpg', 'png'], return_absolute_filepath=True)
Loop over multiple directories
This package is not recursive - if you want to process multiple directories you have to do it yourself:
from get_all_files import get_all_files
from pathlib import Path
import os
home_dir = Path('~').expanduser()
subfolders = [f.path for f in os.scandir(home_dir) if f.is_dir()]
extension = 'txt' # why not
all_files = []
for folder in subfolders:
files = get_all_files(folder, extension, return_absolute_filepath=True)
all_files.extend(files)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for get_all_files-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05243d9cb2f48657d667b672a2bf14687e955c526aba7fc2e53545cd8d17b7ba |
|
MD5 | 9fa889150dbd881d024eee5e33d9156e |
|
BLAKE2b-256 | 43a8409078b8744a0de6c66383d9443631fc99a56fbd5cccd68ba3d122780da2 |