Cross-platform file operations toolkit with path handling, verification, and metadata preservation
- Path Operations: Cross-platform path handling, normalization, and manipulation
- File Operations: Copy, move, and manage files with metadata preservation
- File Verification: Calculate and verify file hashes (MD5, SHA1, SHA256, SHA512)
- Platform Support: Windows, Linux, and macOS with platform-specific optimizations
- UNC Path Support: Optional integration with
unctoolsfor Windows UNC path handling - Metadata Preservation: Preserve timestamps, permissions, and file attributes
While Python's standard library (shutil, pathlib, os) provides basic file operations, dazzle-filekit offers:
- Metadata Preservation: Automatic preservation of timestamps, permissions, and extended attributes across platforms
- Hash Verification: Built-in file verification with multiple hash algorithms (MD5, SHA1, SHA256, SHA512)
- Cross-Platform Path Handling: Unified API for handling Windows UNC paths, network drives, and Unix paths
- Batch Operations: Process entire directory trees with pattern matching and filtering
- Safe Operations: Built-in conflict resolution, unique path generation, and error handling
- Directory Comparison: Compare directory contents and verify file integrity across locations
dazzle-filekit was designed for applications requiring reliable file operations with verification, such as backup tools, file synchronization, and data preservation systems (like the preserve project).
pip install dazzle-filekitFor Windows UNC path support:
pip install dazzle-filekit[unctools]For development:
pip install dazzle-filekit[dev]from dazzle_filekit import normalize_path, find_files, is_unc_path
# Normalize paths (returns Path object)
path = normalize_path("/some/path/../file.txt")
print(path) # PosixPath('/some/file.txt') or WindowsPath('C:/some/file.txt')
# Find files with patterns (returns list of path strings)
files = find_files("/directory", patterns=["*.py", "*.txt"])
# Check UNC paths
if is_unc_path(r"\\server\share"):
print("This is a UNC path")from dazzle_filekit import copy_file, collect_file_metadata
# Copy file with metadata preservation
success = copy_file("source.txt", "dest.txt", preserve_metadata=True)
# Collect file metadata
metadata = collect_file_metadata("file.txt")
print(f"Size: {metadata['size']}, Modified: {metadata['mtime']}")from dazzle_filekit import calculate_file_hash, verify_file_hash
# Calculate hash
hash_value = calculate_file_hash("file.txt", algorithm="sha256")
# Verify hash
is_valid = verify_file_hash("file.txt", expected_hash, algorithm="sha256")normalize_path(path)- Normalize path to canonical formis_same_file(path1, path2)- Check if paths refer to same filesplit_drive_letter(path)- Split drive letter from path (Windows)is_unc_path(path)- Check if path is UNC formatget_relative_path(path, base)- Get relative path from basefind_files(directory, patterns, exclude)- Find files matching patternsget_path_type(path)- Detect path type (unc, network, subst, local)
copy_file(src, dst, preserve_metadata)- Copy file with optionsmove_file(src, dst, preserve_metadata)- Move file with optionscollect_file_metadata(path)- Collect file metadataapply_file_metadata(path, metadata)- Apply metadata to filecreate_directory_structure(path)- Create directory treeremove_file(path)- Remove file safelyremove_directory(path, recursive)- Remove directory
calculate_file_hash(path, algorithm)- Calculate file hashverify_file_hash(path, expected_hash, algorithm)- Verify hashcalculate_directory_hashes(directory, algorithm)- Hash all files in directorysave_hashes_to_file(hashes, output_file)- Save hashes to fileload_hashes_from_file(hash_file)- Load hashes from filecompare_directories(dir1, dir2)- Compare directory contentsverify_copied_files(src_dir, dst_dir)- Verify copy operation
- Full UNC path support (with
unctools) - Network drive detection
- NTFS metadata preservation
- Long path support (>260 characters)
- POSIX permissions preservation
- Symlink handling
- Extended attributes
- HFS+ and APFS support
- Extended attributes
- Resource forks (where applicable)
from dazzle_filekit import configure_logging, enable_verbose_logging
import logging
# Configure logging level
configure_logging(level=logging.DEBUG, log_file="dazzle-filekit.log")
# Or enable verbose logging
enable_verbose_logging()git clone https://github.com/DazzleLib/dazzle-filekit.git
cd dazzle-filekit/local
pip install -e ".[dev]"pytest tests/ -v --cov=dazzle_filekitblack dazzle_filekit tests
flake8 dazzle_filekit testsContributions are welcome! Please see CONTRIBUTING.md for guidelines.
Like the project?
This project is licensed under the MIT License - see the LICENSE file for details.
dazzle-filekit is part of the DazzleLib ecosystem of Python file manipulation tools.
- UNCtools - Windows UNC path utilities
- dazzle-tree-lib - Tree structure utilities
- preserve - File preservation tool using dazzle-filekit