Skip to main content

No project description provided

Project description

Series

pathobj_handler.filestem.picker

  • PickFilesBySuffix

pathobj_handler.filesterm.filter

  • FilterByCustomFunction
  • FilterWithDateRange
  • FilterWithRegExp

pathobj_handler.filestem.renamer

  • RenameFilesByCustomFunction

PickFilesBySuffix can retrieve file objects in a given directory, and FilterByCustomFunction can filter file objects by their file names.

pathobj_hundler classes form a process chain with the make_pipeline function. The chain can contain several filters, and each of the filters applies to a file object in an order.

Basic use

Listing *.txt or *.text files in the given directory tree:

from pathobj_handler.filestem.picker import PickFilesBySuffix

fp = PickFilesBySuffix(['.txt', '.text'], recursive=True)
dir_path = './resource'

fp_gen = fp(dir_path)
print(list(fp_gen))

[WindowsPath('resource/sample/20240410T150525_DDDDDD111111_AAA.txt'), WindowsPath('resource/sample/20240411T150625_DDDDDD111111_BBB.txt'), WindowsPath('resource/sample/20240412T150725_DDDD DD222222_AAA.txt'), WindowsPath('resource/sample/20240413T150825_DDDDDD333333_BBB.txt'), WindowsPath('resource/sample/fuga_01.txt'), WindowsPath('resource/sample/fuga_02.txt'), WindowsPath('resource/sample/hoge_01.text'), WindowsPath('resource/sample/hoge_02.text')]


Screening files in a given directory that contain the specified string in the filename:

from pathobj_handler.tool import make_pipeline
from pathobj_handler.filestem.picker import PickFilesBySuffix
from pathobj_handler.filestem.filter import FilterByCustomFunction

fp = PickFilesBySuffix(['.txt', '.text'], recursive=True)
dir_path = './resource'

# custom filter
def is_target(stem: str) -> bool:
    return 'hoge' in stem

fl_1 = FilterByCustomFunction(filter_method=is_target)

fp_filter = make_pipeline(fp, fl_1)
fp_gen = fp_filter(dir_path)
print(list(fp_gen))

[WindowsPath('resource/sample/hoge_01.text'), WindowsPath('resource/sample/hoge_02.text')]


Multiple filters are chained with make_pipeline:

from datetime import datetime
import re

from pathobj_handler.tool import make_pipeline
from pathobj_handler.filestem.picker import PickFilesBySuffix
from pathobj_handler.filestem.filter import FilterWithDateRange, FilterWithRegExp

fp = PickFilesBySuffix(['.txt', '.text'], recursive=True)
dir_path = './resource'

fl_1 = FilterWithDateRange(
    re_time=r'\d+T\d+',
    dt_from=datetime(2024, 4, 11),
    dt_to=datetime(2024, 4, 13),
)

fl_2 = FilterWithRegExp(
    re_list=['DDDDDD111111', 'DDDDDD333333']
)

fp_filter = make_pipeline(
    fp, 
    fl_1,
    fl_2,
)
fp_gen = fp_filter(dir_path)
print(list(fp_gen))

[WindowsPath('resource/sample/20240411T150625_DDDDDD111111_BBB.txt')]


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

pathobj_handler-1.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

pathobj_handler-1.0.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pathobj_handler-1.0.0.tar.gz.

File metadata

  • Download URL: pathobj_handler-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.0

File hashes

Hashes for pathobj_handler-1.0.0.tar.gz
Algorithm Hash digest
SHA256 dd0673597fc83e223cd06f8d61caaaa35651fba4dd1ad6fff14bc78f1795c6e8
MD5 be2316785061702ffe919e0eed95f7cf
BLAKE2b-256 eb3384044a3109f8539fa7e08badd88cc3c40f4c7c230134a48de27037e5a062

See more details on using hashes here.

File details

Details for the file pathobj_handler-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pathobj_handler-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac8aa33e7d630c78fce19159a6f11e793c2cd967ec990c210ba2e137a58a0899
MD5 2efa46e26e49eae99ced2859e07f0baf
BLAKE2b-256 80607810439c01eb703af5d18800429df1e0a93a227a804654860e250060fb04

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