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 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 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
File details
Details for the file get_all_files-0.1.0.tar.gz
.
File metadata
- Download URL: get_all_files-0.1.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97dcf94076327f85530dece569fb3bb630584702e955afa9aa42e3e8dc22e075 |
|
MD5 | 6831bec97673a1e8bb1005557a258b81 |
|
BLAKE2b-256 | b5024466d331df0e670ee29cd91a714722815f7d6a1514367ae9064eefb9f8c0 |
File details
Details for the file get_all_files-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: get_all_files-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3ccc237e14c596376778417456ba0bf1eb3e212c57f1ecc6363742a8c0d8774 |
|
MD5 | ad2e692f97c541d275e88ef188eb3b08 |
|
BLAKE2b-256 | 02de3b7a02e5202ed5956b1717c0d082a9b8b0b25001b04139f4e7e97fa2ff3b |