Path utilities for Python

0.1.2 · abandoned · verified Mon Apr 13

Pathtools is a Python library providing pattern matching and various utilities for file system paths. The library is currently at version 0.1.2 and was last updated in 2011, indicating an abandoned or extremely slow release cadence.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `filter_paths` from `pathtools.patterns` to filter a list of file paths based on inclusion and exclusion patterns.

import os
from pathtools.patterns import filter_paths

# Create some dummy files for demonstration
os.makedirs("temp_dir", exist_ok=True)
with open("temp_dir/file1.txt", "w") as f: f.write("test")
with open("temp_dir/image.png", "w") as f: f.write("test")
with open("temp_dir/document.pdf", "w") as f: f.write("test")

all_paths = [
    "temp_dir/file1.txt",
    "temp_dir/image.png",
    "temp_dir/document.pdf",
    "temp_dir/another.txt",
    "ignore_me.log"
]

# Filter paths to include only .txt files and exclude 'ignore_me.log'
included_patterns = ['*.txt']
excluded_patterns = ['*ignore_me.log']

filtered = filter_paths(all_paths, included_patterns, excluded_patterns)
print(list(filtered))

# Clean up
os.remove("temp_dir/file1.txt")
os.remove("temp_dir/image.png")
os.remove("temp_dir/document.pdf")
os.rmdir("temp_dir")

view raw JSON →