Skip to main content

Get Files List

Python package that provides a utility function to recursively get files that match a pattern.

Installation

Install using pip:

pip install get_files_list

Usage

Example of this package usage in a folder with the following structure:

 ├──      LICENSE
 ├──      README.md
 ├──      deploy.sh
 └──      get_files_list/
 │  ├────      __init__.py
 │  └────      get_dir_content.py
 ├──      requirements.in
 ├──      requirements.txt
 └──      setup.py

The following code:

from get_files_list import get_dir_content

# Print every file
print("Print every file\n")
for file in get_dir_content("./"):
    print(file)

# Print everyPython file
print("\n\nPrint every Python file\n")
for file in get_dir_content("./", pattern="*.py"):
    print(file)

# Print every Python file without the prepended folder name
print("\n\nPrint every Python file without the prepended folder name\n")
for file in get_dir_content("./", prepend_folder_name=False, pattern="*.py"):
    print(file)

# Print every file without recursion
print("\n\nPrint every file without recursion\n")
for file in get_dir_content("./", recursive=False):
    print(file)

# Print every file that is not a Python file
print("\n\nPrint every file that is not a Python file\n")
for file in get_dir_content("./", exclude_pattern="*.py"):
    print(file)

Would output:

Print every file

./LICENSE
./requirements.txt
./get_files_list/get_dir_content.py
./get_files_list/__init__.py
./README.md
./setup.py
./deploy.sh
./requirements.in


Print every python file

./get_files_list/get_dir_content.py
./get_files_list/__init__.py
./setup.py


Print every python file without the prepended folder name

get_files_list/get_dir_content.py
get_files_list/__init__.py
setup.py


Print every file without recursion

./LICENSE
./requirements.txt
./README.md
./setup.py
./deploy.sh
./requirements.in


Print every file that is not a Python file

./LICENSE
./requirements.txt
./README.md
./deploy.sh
./requirements.in

Generator

get_dir_content is a Python generator so the following code would not work:

from get_files_list import get_dir_content

num_py_files = len(get_dir_content("./", pattern="*.py"))
# TypeError: object of type 'generator' has no len()

# You have to explicitely generate a list
num_py_files = len(list(get_dir_content("./", pattern="*.py")))
# This works

This is also valid if you want to order, shuffle or slice the list of files.

Inspiration

This code is inspired by this StackOverflow Question/Answer.

Metadata

Release files for get-files-list 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for get-files-list 0.3.1
File Size Uploaded
get_files_list-0.3.1.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for get-files-list 0.3.1
File Interpreter ABI Platform
get_files_list-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / get_files_list-0.3.1.tar.gz

Download URL get_files_list-0.3.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b5b31e25d491a08a69ba49c37464b9fb08670c0e6898ed58224613db68261263
BLAKE2b-256 checksum
How to use checksums
c07aeb573928c14ce90d8b7a95c470a882b736e6fdba1dc53d5682c228122fef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / get_files_list-0.3.1-py3-none-any.whl

Download URL get_files_list-0.3.1-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
989942a8a0bc9bf600d0e39ce6be437f6b974fb96569c8c6bfa36c0c648cb03a
BLAKE2b-256 checksum
How to use checksums
490a08ad6939df631d4486dfca35b54d0016b5c709f8e293812026fe75181596
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

3 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page