Skip to main content

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

Project description

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.

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

get_files_list-0.1.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

get_files_list-0.1.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file get_files_list-0.1.1.tar.gz.

File metadata

  • Download URL: get_files_list-0.1.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for get_files_list-0.1.1.tar.gz
Algorithm Hash digest
SHA256 26f319bf9d4910be9e95a1f88b45891943ee9928e4f2929614df7c104435d0dd
MD5 9d968b321ec51f1bf66659f8e0facda8
BLAKE2b-256 1a793e4e86e820f3b8dc1d024ac1a28fced3433c0cb45cd6e910b25f288d114d

See more details on using hashes here.

File details

Details for the file get_files_list-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for get_files_list-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f3d2ff881b02c2f658e3e2f96eb0f92ceccb3e560784d36b42ffc303684e3efa
MD5 77e28f350555c67757510da2e2afbd03
BLAKE2b-256 774233daa956ae4a00582e2f67fe75f95230a73405da4ceda8ca0d5cdc0b4f1a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page