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
  • RenamerWithReplaceStr

`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.1.tar.gz (5.8 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.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pathobj_handler-1.0.1.tar.gz
  • Upload date:
  • Size: 5.8 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.1.tar.gz
Algorithm Hash digest
SHA256 fc0550f54f99561efd53a9b1ffcc045fab31a5de40158e774069e2abdee84950
MD5 e8aec4290ea68307a5c7bce257bde611
BLAKE2b-256 2b212f689fc5a7a42e0bc0080c68357be9ec35408c2efc6f730855f4960ef6c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pathobj_handler-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 09ba95c7bfe5175494a6930a5588e67bd890f3a9b66231a045a6eea6e472c7f8
MD5 cc6e197fade91b00f4fe5748538cde8b
BLAKE2b-256 f35f74bca9cd7ed5b956ba566cc37d224ddb900b4e804d7a2787d7d97706de1e

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