Agent skill
pathlib
Object-oriented filesystem paths
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/fixtures-skilldoai-skilldo-2
SKILL.md
Imports
from pathlib import Path
import os
Core Patterns
Basic Path Creation
Create and manipulate filesystem paths.
from pathlib import Path
# Create a path
p = Path('/tmp/example.txt')
# Check if it exists
if p.exists():
print(f"File exists: {p}")
# Get parts
print(f"Name: {p.name}")
print(f"Parent: {p.parent}")
Reading Files
Read file contents using Path.
from pathlib import Path
p = Path('/tmp/example.txt')
# Write
p.write_text('Hello World!')
# Read
content = p.read_text()
print(f"Content: {content}")
Directory Iteration
Iterate over files in a directory.
from pathlib import Path
# List all Python files
for file in Path('.').glob('*.py'):
print(f"Found: {file.name}")
Configuration
Path objects are immutable and work consistently across platforms.
Pitfalls
Wrong: Using string concatenation for paths
path = '/tmp' + '/' + 'file.txt' # Platform-specific
Right: Use Path division operator
from pathlib import Path
path = Path('/tmp') / 'file.txt' # Cross-platform
References
- Official Documentation: https://docs.python.org/3/library/pathlib.html
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?