Python pathlib Module

The pathlib module provides object-oriented filesystem path handling. Introduced in Python 3.4, it offers an elegant alternative to os.path for working with file and directory paths. Path objects represent filesystem paths with semantics appropriate for the operating system.

Use Cases:
- Reading and writing files without manual string concatenation
- Navigating directory trees and listing files by pattern
- Creating, renaming, and deleting files and directories
- Cross-platform path handling (Windows backslashes vs Unix forward slashes)
- Checking file existence, permissions, and metadata

Example 1: Reading a file
    from pathlib import Path
    config = Path("settings.json")
    if config.exists():
        data = config.read_text(encoding="utf-8")
        print(f"Config loaded: {len(data)} characters")

Example 2: Listing Python files recursively
    from pathlib import Path
    project = Path("/home/user/project")
    py_files = sorted(project.rglob("*.py"))
    for f in py_files:
        print(f"  {f.relative_to(project)} ({f.stat().st_size} bytes)")

Key classes include Path (the main cross-platform class), PurePosixPath, and PureWindowsPath for platform-specific path logic without filesystem access. The module integrates well with open(), shutil, and other stdlib functions that accept path-like objects.
