Wcmatch - Wildcard/Glob File Name Matcher

10.1 · active · verified Sun Mar 29

Wcmatch is a Python library that provides enhanced `fnmatch`, `glob`, and `pathlib` functionalities, closely following Bash-like wildcard and glob matching features. It includes support for recursive globs (`**`), Zsh-style symlink traversal (`***`), brace expansion, extended glob patterns, and more. The library is actively maintained with regular releases, often adding new features and dropping support for older Python versions.

Warnings

Install

Imports

Quickstart

Demonstrates basic recursive globbing, including how to match hidden files, and a simple string match using `fnmatch`. This creates a temporary directory structure for the example.

import os
import shutil
from wcmatch import glob, fnmatch

# Create some dummy files/directories for the example
os.makedirs('temp_dir/nested/.hidden', exist_ok=True)
with open('temp_dir/file.txt', 'w') as f: f.write('hi')
with open('temp_dir/nested/another.log', 'w') as f: f.write('hi')
with open('temp_dir/nested/.hidden/secret.dat', 'w') as f: f.write('hi')

print("Basic recursive glob (glob.GLOBSTAR):")
# By default, doesn't match hidden files or symlinks
# Output may vary based on OS and actual symlinks
results_globstar = glob.glob('temp_dir/**/*.txt', flags=glob.GLOBSTAR)
print(f"Found: {sorted(results_globstar)}")
# Expected: ['temp_dir/file.txt']

print("\nRecursive glob including hidden files (GLOBSTAR | DOTGLOB):")
results_hidden = glob.glob('temp_dir/**/*', flags=glob.GLOBSTAR | glob.DOTGLOB)
print(f"Found: {sorted(results_hidden)}")
# Expected: Should include 'temp_dir/.hidden/secret.dat', 'temp_dir/file.txt', 'temp_dir/nested/another.log', etc.

print("\nString matching with fnmatch:")
match_str = fnmatch.fnmatch('image.jpeg', '*.jp*g')
print(f"'image.jpeg' matches '*.jp*g': {match_str}")
# Expected: True

# Clean up
shutil.rmtree('temp_dir')

view raw JSON →