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.3.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

get_files_list-0.3.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: get_files_list-0.3.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for get_files_list-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b5b31e25d491a08a69ba49c37464b9fb08670c0e6898ed58224613db68261263
MD5 2a31808d83574c427823e5f2b3c65dca
BLAKE2b-256 c07aeb573928c14ce90d8b7a95c470a882b736e6fdba1dc53d5682c228122fef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: get_files_list-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for get_files_list-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 989942a8a0bc9bf600d0e39ce6be437f6b974fb96569c8c6bfa36c0c648cb03a
MD5 c4489babe8f466fc656a0c0d01585f1e
BLAKE2b-256 490a08ad6939df631d4486dfca35b54d0016b5c709f8e293812026fe75181596

See more details on using hashes here.

Supported by

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