Repository files navigation

doFolder

PyPI versionGitHub RepositoryGitHub top languageLicenseDocumentation Status

doFolder is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's pathlib, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

✨ Key Features

  • 🎯 Object-oriented Design: Work with files and directories as Python objects
  • 🌐 Cross-platform Compatibility: Seamlessly works on Windows, macOS, and Linux
  • 🛤️ Advanced Path Handling: Built on Python's pathlib for robust path management
  • 📁 Complete File Operations: Create, move, copy, delete, and modify files and directories
  • 📝 Content Management: Read and write file content with encoding support
  • 🌳 Directory Tree Operations: Navigate and manipulate directory structures
  • 🔍 File Comparison: Compare files and directories with various comparison modes
  • 🔒 Hash Support: Generate and verify file hashes for integrity checking with multi-algorithm support
  • ⚡ High-Performance Hashing: Multi-threaded hash calculation with intelligent caching and progress tracking
  • 🖥️ Command-Line Tools: Comprehensive CLI interface with direct commands (do-compare, do-hash) and unified interface (do-folder)
  • ⚠️ Flexible Error Handling: Comprehensive error modes for different use cases
  • 🏷️ Type Safety: Full type hints for better IDE support and code reliability

📦 Installation

pip install doFolder

Requirements: Python 3.9+

Note: Python 3.8 is no longer supported since version 2.3.0

🚀 Quick Start

Command-Line Quick Start

After installation, you can immediately start using doFolder's command-line tools:

# Compare two directories
do-compare /path/to/source /path/to/backup
# Compare and sync directories
do-compare /path/to/source /path/to/backup --sync --sync-direction A2B
# Calculate file hashes
do-hash file1.txt file2.txt
# Calculate with specific algorithms
do-hash -a sha256,md5 README.md README.zh-cn.md
# Hash all files in a directory recursively
do-hash -r -d /path/to/project
# Use unified interface
do-folder compare /dir1 /dir2 --compare-mode CONTENT
do-folder hash -a blake2b *.py
# Or
python -m doFolder compare /dir1 /dir2 --compare-mode CONTENT
python -m doFolder hash -a blake2b *.py
# Note: do-folder is equal to python -m doFolder, use any of them you like

Python Quick Start

fromdoFolderimportFile, Directory, ItemType# Create directory and file objectsproject_dir=Directory("./my_project")
config_file=project_dir["config.json"]
# Create a new file in the directoryreadme=project_dir.create("README.md", ItemType.FILE)
readme_zh=project_dir.createFile("README.zh-cn.md")
# Write content to the filereadme.content="# My Project\n\nWelcome to my project!".encode("utf-8")
# Create a subdirectorysrc_dir=project_dir.create("src", ItemType.DIR)
# Copy and move filesbackup_config=config_file.copy("./backup/")
config_file.move("./settings/")
# List directory contentsforiteminproject_dir:
print(f"{item.name} ({'Directory'ifitem.isDirelse'File'})")

📖 Usage Examples

Working with Files

fromdoFolderimportFile# Create a file objectfile=File("data.txt")
# Work with binary contentprint(file.content) # Reads content as bytesfile.content="Binary data here".encode("utf-8") # Writes content as bytes# JSON operationsfile.saveAsJson({"name": "John", "age": 30})
data=file.loadAsJson()
# Quickly open filewithfile.open("w", encoding="utf-8") asf:
f.write("Hello, World!")
# File informationprint(f"Size: {file.state.st_size} bytes")
print(f"Modified: {file.state.st_mtime}")
# File hashingprint(f"Hash: {file.hash()}")
print(f"SHA256: {file.hash('sha256')}")
print(f"MD5: {file.hash('md5')}")
# Multi-threaded hashing for better performancefromdoFolder.hashingimportThreadedFileHashCalculatorwithThreadedFileHashCalculator(threadNum=4) ascalculator:
result=calculator.get(file)
print(f"Threaded hash: {result.hash}")

Working with Directories

fromdoFolderimportDirectory, ItemType# Create a directory objectd=Directory("./workspace")
# Create nested directory structured.create("src/utils", ItemType.DIR)
d.create("tests", ItemType.DIR)
d.createDir("docs")
d.createFile("README.md")
# Create filesmain_file=d.create("src/main.py", ItemType.FILE)
test_file=d.create("tests/test_main.py", ItemType.FILE)
# List all items (non-recursive)foritemind:
print(item.path)
# List all items recursivelyforitemind.recursiveTraversal(hideDirectory=False):
print(f"{'📁'ifitem.isDirelse'📄'}{item.path}")
# Find specific sub itemspy_files= ['__init__.py']

Command-Line Operations

doFolder provides powerful command-line tools for file system operations:

# Compare two directories with different modes
do-folder compare /path/to/dir1 /path/to/dir2 --compare-mode CONTENT
do-compare /path/to/dir1 /path/to/dir2 --sync --sync-direction A2B
# Calculate file hashes with multiple algorithms
do-folder hash -a sha256,md5 file1.txt file2.txt
do-hash -a blake2b -r /path/to/directory
# Use threading for better performance on large files
do-hash -n 8 -d -r -a sha256 /path/to/large_files/
# Options: -n: number of threads, -d: allow directory, -r: recursive

Advanced Operations

fromdoFolderimportFile, Directory, comparefromdoFolder.hashingimportFileHashCalculator, multipleFileHash# File comparisonfile1=File("version1.txt")
file2=File("version2.txt")
ifcompare.compare(file1, file2):
print("Files are identical")
else:
print("Files differ")
# Directory comparison with detailed difference analysisdir1=Directory("./project_v1")
dir2=Directory("./project_v2")
diff=compare.getDifference(dir1, dir2)
ifdiff:
# Print all differences in flat structurefordindiff.toFlat():
print(f"Difference: {d.path1} vs {d.path2} - {d.diffType}")
# Advanced hashing with caching and multiple algorithmscalculator=FileHashCalculator()
file=File("important_data.txt")
# Single algorithmresult=calculator.get(file, "sha256")
print(f"SHA256: {result.hash}")
# Cached hashing for better performanceprint(f"The second result: {calculator.get(file).hash}")
file.content="New content".encode("utf-8")
# The cache will invalidate when file content changesprint(f"The third result: {calculator.get(file).hash}")
# Multiple algorithms at once (only one disk read is needed)results=calculator.multipleGet(file, ["sha256", "md5", "blake2b"])
foralgo, resultinresults.items():
print(f"{algo.upper()}: {result.hash}")

Path Utilities

Since v2.0.0, doFolder.Path is an alias for Python's built-in pathlib.Path, instead of the custom specialStr.Path from older versions.

For detailed information, please see pathlib documentation.

💻 Command-Line Interface

doFolder provides powerful command-line tools for file system operations with both unified and direct command interfaces.

Installation & Usage

After installing doFolder, you get access to several command-line tools:

# Install doFolder
pip install doFolder
# Direct commands (shortcuts)
do-compare /path1 /path2 # File/directory comparison
do-hash file.txt # File hashing# Unified interface
do-folder compare /path1 /path2 # Same as do-compare
do-folder hash file.txt # Same as do-hash# Python module interface
python -m doFolder compare /path1 /path2
python -m doFolder hash file.txt

Compare Command

Compare files or directories with various options:

# Basic comparison
do-compare file1.txt file2.txt
do-compare /directory1 /directory2
# Different comparison modes
do-compare /dir1 /dir2 --compare-mode CONTENT # Compare file contents
do-compare /dir1 /dir2 --compare-mode SIZE # Compare file sizes
do-compare /dir1 /dir2 --compare-mode TIMETAG # Compare modification times# Synchronization
do-compare /source /backup --sync --sync-direction A2B # Sync A to B
do-compare /dir1 /dir2 --sync --sync-direction BOTH # Bidirectional sync# Overwrite handling
do-compare /dir1 /dir2 --sync --overwrite AUTO # Auto decide by timestamp
do-compare /dir1 /dir2 --sync --overwrite ASK # Ask for each conflict

Hash Command

Calculate file hashes with multiple algorithms and options:

# Basic hashing (uses SHA256 by default)
do-hash file.txt
# Multiple algorithms
do-hash -a sha256,md5,sha1 file.txt
do-hash -a blake2b important_document.txt -a md5,sha1 another_file.txt
# Directory hashing
do-hash -d /directory # Hash all file in directory(no recursion)
do-hash -r -d /project # Recursive directory hashing# Performance options
do-hash -n 8 -d -a sha256,md5,blake2b ./src
# Disable progress display for cleaner output
do-hash --no-progress -r -d /path/to/files
# Path formatting
do-hash -p /absolute/path/file.txt # Use absolute paths
do-hash -f file.txt # Always show full path

Global Options

All commands support these global options:

# Version information
do-folder -v # Show version
do-folder -vv # Show detailed version info# Output control
do-folder --no-color compare /dir1 /dir2 # Disable colored output
do-folder -w 120 hash file.txt # Set console width
do-folder -m hash file.txt # Mute warnings
do-folder -t compare /dir1 /dir2 # Show full traceback on errors

Practical Examples

Backup Verification:

# Compare original and backup, sync differences
do-compare /important/data /backup/data --sync --sync-direction A2B --overwrite AUTO

Development Workflow:

# Compare two versions of a project
do-compare /project/v1 /project/v2 --compare-mode CONTENT
# Hash all source files for change detection
do-hash -a blake2b -r /src --full-path

�🔧 Advanced Features

Command-Line Interface

doFolder provides comprehensive command-line tools with two usage modes:

Unified Interface:

# Main command with subcommands
do-folder compare /path/to/dir1 /path/to/dir2 --sync
do-folder hash -a sha256,md5 file1.txt file2.txt
# Using Python module
python -m doFolder compare /source /backup --compare-mode CONTENT
python -m doFolder hash -a blake2b -r /directory

Direct Commands:

# Direct command shortcuts
do-compare /path/to/dir1 /path/to/dir2 --sync --overwrite AUTO
do-hash -a sha256,md5 file1.txt file2.txt --thread-num 8

Compare Command Features

  • Multiple comparison modes (SIZE, CONTENT, TIMETAG, TIMETAG_AND_SIZE, IGNORE)
  • Directory synchronization with bidirectional support
  • Flexible overwrite policies (A2B, B2A, ASK, AUTO, IGNORE)
  • Relative timestamp formatting
  • Interactive conflict resolution

Hash Command Features

  • Support for multiple hash algorithms (SHA family, MD5, BLAKE2, SHA3, etc.)
  • Multi-threaded processing for performance
  • Recursive directory hashing
  • Progress tracking with detailed status
  • Flexible output formatting

Advanced Hashing System

doFolder includes a sophisticated hashing system with multiple optimization levels:

fromdoFolder.hashingimport (
FileHashCalculator,
ThreadedFileHashCalculator,
ReCalcHashMode,
MemoryFileHashManager
)
fromconcurrent.futuresimportwait# Basic calculator with cachingcalculator=FileHashCalculator(
algorithm="sha256",
useCache=True,
reCalcHashMode=ReCalcHashMode.TIMETAG# Only recalc if file modified
)
# Multi-threaded calculator for better performancewithThreadedFileHashCalculator(threadNum=8) asthreaded_calc:
# Process multiple files concurrentlyfutures= [threaded_calc.threadedGet(file) forfileinfile_list]
wait(futures)
results= [future.result() forfutureinfutures]
# Custom cache managerfromdoFolder.hashingimportLfuMemoryFileHashManagercalculator=FileHashCalculator(
cacheManager=LfuMemoryFileHashManager(maxSize=1000)
)

Error Handling Modes

doFolder provides flexible error handling through UnExistsMode:

fromdoFolderimportFile, UnExistsMode# Different modes for handling non-existent filesfile1=File("missing.txt", unExistsMode=UnExistsMode.ERROR) # Raises exceptionfile2=File("missing.txt", unExistsMode=UnExistsMode.WARN) # Issues warningfile3=File("missing.txt", unExistsMode=UnExistsMode.IGNORE) # Silent handlingfile4=File("missing.txt", unExistsMode=UnExistsMode.CREATE) # Creates if missing

File System Item Types

fromdoFolderimportItemType, createItem# Factory function to create appropriate objectsitem1=createItem("./some_path", ItemType.FILE) # Creates File objectitem2=createItem("./some_path", ItemType.DIR) # Creates Directory objectitem3=createItem("./some_path") # Auto-detects type

🔄 Migration from v1.x.x

doFolder v2.x.x introduces several improvements while maintaining backward compatibility:

  • Enhanced Path Management: Now uses Python's built-in pathlib
  • Renamed Classes: FolderDirectory (backward compatibility maintained)
  • Flexible File Creation: File class can handle directory paths with redirection
  • Improved Type Safety: Full type hints throughout the codebase

Migration Example

# v1.x.x style (still works)fromdoFolderimportFolderfolder=Folder("./my_directory")
# v2.x.x recommended stylefromdoFolderimportDirectorydirectory=Directory("./my_directory")
# Both work identically!

📚 Documentation

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MulanPSL-2.0 License - see the LICENSE file for details.

About

It is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's `pathlib`, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

doFolder

PyPI versionGitHub RepositoryGitHub top languageLicenseDocumentation Status

doFolder is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's pathlib, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

✨ Key Features

  • 🎯 Object-oriented Design: Work with files and directories as Python objects
  • 🌐 Cross-platform Compatibility: Seamlessly works on Windows, macOS, and Linux
  • 🛤️ Advanced Path Handling: Built on Python's pathlib for robust path management
  • 📁 Complete File Operations: Create, move, copy, delete, and modify files and directories
  • 📝 Content Management: Read and write file content with encoding support
  • 🌳 Directory Tree Operations: Navigate and manipulate directory structures
  • 🔍 File Comparison: Compare files and directories with various comparison modes
  • 🔒 Hash Support: Generate and verify file hashes for integrity checking with multi-algorithm support
  • ⚡ High-Performance Hashing: Multi-threaded hash calculation with intelligent caching and progress tracking
  • 🖥️ Command-Line Tools: Comprehensive CLI interface with direct commands (do-compare, do-hash) and unified interface (do-folder)
  • ⚠️ Flexible Error Handling: Comprehensive error modes for different use cases
  • 🏷️ Type Safety: Full type hints for better IDE support and code reliability

📦 Installation

pip install doFolder

Requirements: Python 3.9+

Note: Python 3.8 is no longer supported since version 2.3.0

🚀 Quick Start

Command-Line Quick Start

After installation, you can immediately start using doFolder's command-line tools:

# Compare two directories
do-compare /path/to/source /path/to/backup
# Compare and sync directories
do-compare /path/to/source /path/to/backup --sync --sync-direction A2B
# Calculate file hashes
do-hash file1.txt file2.txt
# Calculate with specific algorithms
do-hash -a sha256,md5 README.md README.zh-cn.md
# Hash all files in a directory recursively
do-hash -r -d /path/to/project
# Use unified interface
do-folder compare /dir1 /dir2 --compare-mode CONTENT
do-folder hash -a blake2b *.py
# Or
python -m doFolder compare /dir1 /dir2 --compare-mode CONTENT
python -m doFolder hash -a blake2b *.py
# Note: do-folder is equal to python -m doFolder, use any of them you like

Python Quick Start

fromdoFolderimportFile, Directory, ItemType# Create directory and file objectsproject_dir=Directory("./my_project")
config_file=project_dir["config.json"]
# Create a new file in the directoryreadme=project_dir.create("README.md", ItemType.FILE)
readme_zh=project_dir.createFile("README.zh-cn.md")
# Write content to the filereadme.content="# My Project\n\nWelcome to my project!".encode("utf-8")
# Create a subdirectorysrc_dir=project_dir.create("src", ItemType.DIR)
# Copy and move filesbackup_config=config_file.copy("./backup/")
config_file.move("./settings/")
# List directory contentsforiteminproject_dir:
print(f"{item.name} ({'Directory'ifitem.isDirelse'File'})")

📖 Usage Examples

Working with Files

fromdoFolderimportFile# Create a file objectfile=File("data.txt")
# Work with binary contentprint(file.content) # Reads content as bytesfile.content="Binary data here".encode("utf-8") # Writes content as bytes# JSON operationsfile.saveAsJson({"name": "John", "age": 30})
data=file.loadAsJson()
# Quickly open filewithfile.open("w", encoding="utf-8") asf:
f.write("Hello, World!")
# File informationprint(f"Size: {file.state.st_size} bytes")
print(f"Modified: {file.state.st_mtime}")
# File hashingprint(f"Hash: {file.hash()}")
print(f"SHA256: {file.hash('sha256')}")
print(f"MD5: {file.hash('md5')}")
# Multi-threaded hashing for better performancefromdoFolder.hashingimportThreadedFileHashCalculatorwithThreadedFileHashCalculator(threadNum=4) ascalculator:
result=calculator.get(file)
print(f"Threaded hash: {result.hash}")

Working with Directories

fromdoFolderimportDirectory, ItemType# Create a directory objectd=Directory("./workspace")
# Create nested directory structured.create("src/utils", ItemType.DIR)
d.create("tests", ItemType.DIR)
d.createDir("docs")
d.createFile("README.md")
# Create filesmain_file=d.create("src/main.py", ItemType.FILE)
test_file=d.create("tests/test_main.py", ItemType.FILE)
# List all items (non-recursive)foritemind:
print(item.path)
# List all items recursivelyforitemind.recursiveTraversal(hideDirectory=False):
print(f"{'📁'ifitem.isDirelse'📄'}{item.path}")
# Find specific sub itemspy_files= ['__init__.py']

Command-Line Operations

doFolder provides powerful command-line tools for file system operations:

# Compare two directories with different modes
do-folder compare /path/to/dir1 /path/to/dir2 --compare-mode CONTENT
do-compare /path/to/dir1 /path/to/dir2 --sync --sync-direction A2B
# Calculate file hashes with multiple algorithms
do-folder hash -a sha256,md5 file1.txt file2.txt
do-hash -a blake2b -r /path/to/directory
# Use threading for better performance on large files
do-hash -n 8 -d -r -a sha256 /path/to/large_files/
# Options: -n: number of threads, -d: allow directory, -r: recursive

Advanced Operations

fromdoFolderimportFile, Directory, comparefromdoFolder.hashingimportFileHashCalculator, multipleFileHash# File comparisonfile1=File("version1.txt")
file2=File("version2.txt")
ifcompare.compare(file1, file2):
print("Files are identical")
else:
print("Files differ")
# Directory comparison with detailed difference analysisdir1=Directory("./project_v1")
dir2=Directory("./project_v2")
diff=compare.getDifference(dir1, dir2)
ifdiff:
# Print all differences in flat structurefordindiff.toFlat():
print(f"Difference: {d.path1} vs {d.path2} - {d.diffType}")
# Advanced hashing with caching and multiple algorithmscalculator=FileHashCalculator()
file=File("important_data.txt")
# Single algorithmresult=calculator.get(file, "sha256")
print(f"SHA256: {result.hash}")
# Cached hashing for better performanceprint(f"The second result: {calculator.get(file).hash}")
file.content="New content".encode("utf-8")
# The cache will invalidate when file content changesprint(f"The third result: {calculator.get(file).hash}")
# Multiple algorithms at once (only one disk read is needed)results=calculator.multipleGet(file, ["sha256", "md5", "blake2b"])
foralgo, resultinresults.items():
print(f"{algo.upper()}: {result.hash}")

Path Utilities

Since v2.0.0, doFolder.Path is an alias for Python's built-in pathlib.Path, instead of the custom specialStr.Path from older versions.

For detailed information, please see pathlib documentation.

💻 Command-Line Interface

doFolder provides powerful command-line tools for file system operations with both unified and direct command interfaces.

Installation & Usage

After installing doFolder, you get access to several command-line tools:

# Install doFolder
pip install doFolder
# Direct commands (shortcuts)
do-compare /path1 /path2 # File/directory comparison
do-hash file.txt # File hashing# Unified interface
do-folder compare /path1 /path2 # Same as do-compare
do-folder hash file.txt # Same as do-hash# Python module interface
python -m doFolder compare /path1 /path2
python -m doFolder hash file.txt

Compare Command

Compare files or directories with various options:

# Basic comparison
do-compare file1.txt file2.txt
do-compare /directory1 /directory2
# Different comparison modes
do-compare /dir1 /dir2 --compare-mode CONTENT # Compare file contents
do-compare /dir1 /dir2 --compare-mode SIZE # Compare file sizes
do-compare /dir1 /dir2 --compare-mode TIMETAG # Compare modification times# Synchronization
do-compare /source /backup --sync --sync-direction A2B # Sync A to B
do-compare /dir1 /dir2 --sync --sync-direction BOTH # Bidirectional sync# Overwrite handling
do-compare /dir1 /dir2 --sync --overwrite AUTO # Auto decide by timestamp
do-compare /dir1 /dir2 --sync --overwrite ASK # Ask for each conflict

Hash Command

Calculate file hashes with multiple algorithms and options:

# Basic hashing (uses SHA256 by default)
do-hash file.txt
# Multiple algorithms
do-hash -a sha256,md5,sha1 file.txt
do-hash -a blake2b important_document.txt -a md5,sha1 another_file.txt
# Directory hashing
do-hash -d /directory # Hash all file in directory(no recursion)
do-hash -r -d /project # Recursive directory hashing# Performance options
do-hash -n 8 -d -a sha256,md5,blake2b ./src
# Disable progress display for cleaner output
do-hash --no-progress -r -d /path/to/files
# Path formatting
do-hash -p /absolute/path/file.txt # Use absolute paths
do-hash -f file.txt # Always show full path

Global Options

All commands support these global options:

# Version information
do-folder -v # Show version
do-folder -vv # Show detailed version info# Output control
do-folder --no-color compare /dir1 /dir2 # Disable colored output
do-folder -w 120 hash file.txt # Set console width
do-folder -m hash file.txt # Mute warnings
do-folder -t compare /dir1 /dir2 # Show full traceback on errors

Practical Examples

Backup Verification:

# Compare original and backup, sync differences
do-compare /important/data /backup/data --sync --sync-direction A2B --overwrite AUTO

Development Workflow:

# Compare two versions of a project
do-compare /project/v1 /project/v2 --compare-mode CONTENT
# Hash all source files for change detection
do-hash -a blake2b -r /src --full-path

�🔧 Advanced Features

Command-Line Interface

doFolder provides comprehensive command-line tools with two usage modes:

Unified Interface:

# Main command with subcommands
do-folder compare /path/to/dir1 /path/to/dir2 --sync
do-folder hash -a sha256,md5 file1.txt file2.txt
# Using Python module
python -m doFolder compare /source /backup --compare-mode CONTENT
python -m doFolder hash -a blake2b -r /directory

Direct Commands:

# Direct command shortcuts
do-compare /path/to/dir1 /path/to/dir2 --sync --overwrite AUTO
do-hash -a sha256,md5 file1.txt file2.txt --thread-num 8

Compare Command Features

  • Multiple comparison modes (SIZE, CONTENT, TIMETAG, TIMETAG_AND_SIZE, IGNORE)
  • Directory synchronization with bidirectional support
  • Flexible overwrite policies (A2B, B2A, ASK, AUTO, IGNORE)
  • Relative timestamp formatting
  • Interactive conflict resolution

Hash Command Features

  • Support for multiple hash algorithms (SHA family, MD5, BLAKE2, SHA3, etc.)
  • Multi-threaded processing for performance
  • Recursive directory hashing
  • Progress tracking with detailed status
  • Flexible output formatting

Advanced Hashing System

doFolder includes a sophisticated hashing system with multiple optimization levels:

fromdoFolder.hashingimport (
FileHashCalculator,
ThreadedFileHashCalculator,
ReCalcHashMode,
MemoryFileHashManager
)
fromconcurrent.futuresimportwait# Basic calculator with cachingcalculator=FileHashCalculator(
algorithm="sha256",
useCache=True,
reCalcHashMode=ReCalcHashMode.TIMETAG# Only recalc if file modified
)
# Multi-threaded calculator for better performancewithThreadedFileHashCalculator(threadNum=8) asthreaded_calc:
# Process multiple files concurrentlyfutures= [threaded_calc.threadedGet(file) forfileinfile_list]
wait(futures)
results= [future.result() forfutureinfutures]
# Custom cache managerfromdoFolder.hashingimportLfuMemoryFileHashManagercalculator=FileHashCalculator(
cacheManager=LfuMemoryFileHashManager(maxSize=1000)
)

Error Handling Modes

doFolder provides flexible error handling through UnExistsMode:

fromdoFolderimportFile, UnExistsMode# Different modes for handling non-existent filesfile1=File("missing.txt", unExistsMode=UnExistsMode.ERROR) # Raises exceptionfile2=File("missing.txt", unExistsMode=UnExistsMode.WARN) # Issues warningfile3=File("missing.txt", unExistsMode=UnExistsMode.IGNORE) # Silent handlingfile4=File("missing.txt", unExistsMode=UnExistsMode.CREATE) # Creates if missing

File System Item Types

fromdoFolderimportItemType, createItem# Factory function to create appropriate objectsitem1=createItem("./some_path", ItemType.FILE) # Creates File objectitem2=createItem("./some_path", ItemType.DIR) # Creates Directory objectitem3=createItem("./some_path") # Auto-detects type

🔄 Migration from v1.x.x

doFolder v2.x.x introduces several improvements while maintaining backward compatibility:

  • Enhanced Path Management: Now uses Python's built-in pathlib
  • Renamed Classes: FolderDirectory (backward compatibility maintained)
  • Flexible File Creation: File class can handle directory paths with redirection
  • Improved Type Safety: Full type hints throughout the codebase

Migration Example

# v1.x.x style (still works)fromdoFolderimportFolderfolder=Folder("./my_directory")
# v2.x.x recommended stylefromdoFolderimportDirectorydirectory=Directory("./my_directory")
# Both work identically!

📚 Documentation

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MulanPSL-2.0 License - see the LICENSE file for details.

About

It is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's `pathlib`, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

doFolder

PyPI versionGitHub RepositoryGitHub top languageLicenseDocumentation Status

doFolder is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's pathlib, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

✨ Key Features

  • 🎯 Object-oriented Design: Work with files and directories as Python objects
  • 🌐 Cross-platform Compatibility: Seamlessly works on Windows, macOS, and Linux
  • 🛤️ Advanced Path Handling: Built on Python's pathlib for robust path management
  • 📁 Complete File Operations: Create, move, copy, delete, and modify files and directories
  • 📝 Content Management: Read and write file content with encoding support
  • 🌳 Directory Tree Operations: Navigate and manipulate directory structures
  • 🔍 File Comparison: Compare files and directories with various comparison modes
  • 🔒 Hash Support: Generate and verify file hashes for integrity checking with multi-algorithm support
  • ⚡ High-Performance Hashing: Multi-threaded hash calculation with intelligent caching and progress tracking
  • 🖥️ Command-Line Tools: Comprehensive CLI interface with direct commands (do-compare, do-hash) and unified interface (do-folder)
  • ⚠️ Flexible Error Handling: Comprehensive error modes for different use cases
  • 🏷️ Type Safety: Full type hints for better IDE support and code reliability

📦 Installation

pip install doFolder

Requirements: Python 3.9+

Note: Python 3.8 is no longer supported since version 2.3.0

🚀 Quick Start

Command-Line Quick Start

After installation, you can immediately start using doFolder's command-line tools:

# Compare two directories
do-compare /path/to/source /path/to/backup
# Compare and sync directories
do-compare /path/to/source /path/to/backup --sync --sync-direction A2B
# Calculate file hashes
do-hash file1.txt file2.txt
# Calculate with specific algorithms
do-hash -a sha256,md5 README.md README.zh-cn.md
# Hash all files in a directory recursively
do-hash -r -d /path/to/project
# Use unified interface
do-folder compare /dir1 /dir2 --compare-mode CONTENT
do-folder hash -a blake2b *.py
# Or
python -m doFolder compare /dir1 /dir2 --compare-mode CONTENT
python -m doFolder hash -a blake2b *.py
# Note: do-folder is equal to python -m doFolder, use any of them you like

Python Quick Start

fromdoFolderimportFile, Directory, ItemType# Create directory and file objectsproject_dir=Directory("./my_project")
config_file=project_dir["config.json"]
# Create a new file in the directoryreadme=project_dir.create("README.md", ItemType.FILE)
readme_zh=project_dir.createFile("README.zh-cn.md")
# Write content to the filereadme.content="# My Project\n\nWelcome to my project!".encode("utf-8")
# Create a subdirectorysrc_dir=project_dir.create("src", ItemType.DIR)
# Copy and move filesbackup_config=config_file.copy("./backup/")
config_file.move("./settings/")
# List directory contentsforiteminproject_dir:
print(f"{item.name} ({'Directory'ifitem.isDirelse'File'})")

📖 Usage Examples

Working with Files

fromdoFolderimportFile# Create a file objectfile=File("data.txt")
# Work with binary contentprint(file.content) # Reads content as bytesfile.content="Binary data here".encode("utf-8") # Writes content as bytes# JSON operationsfile.saveAsJson({"name": "John", "age": 30})
data=file.loadAsJson()
# Quickly open filewithfile.open("w", encoding="utf-8") asf:
f.write("Hello, World!")
# File informationprint(f"Size: {file.state.st_size} bytes")
print(f"Modified: {file.state.st_mtime}")
# File hashingprint(f"Hash: {file.hash()}")
print(f"SHA256: {file.hash('sha256')}")
print(f"MD5: {file.hash('md5')}")
# Multi-threaded hashing for better performancefromdoFolder.hashingimportThreadedFileHashCalculatorwithThreadedFileHashCalculator(threadNum=4) ascalculator:
result=calculator.get(file)
print(f"Threaded hash: {result.hash}")

Working with Directories

fromdoFolderimportDirectory, ItemType# Create a directory objectd=Directory("./workspace")
# Create nested directory structured.create("src/utils", ItemType.DIR)
d.create("tests", ItemType.DIR)
d.createDir("docs")
d.createFile("README.md")
# Create filesmain_file=d.create("src/main.py", ItemType.FILE)
test_file=d.create("tests/test_main.py", ItemType.FILE)
# List all items (non-recursive)foritemind:
print(item.path)
# List all items recursivelyforitemind.recursiveTraversal(hideDirectory=False):
print(f"{'📁'ifitem.isDirelse'📄'}{item.path}")
# Find specific sub itemspy_files= ['__init__.py']

Command-Line Operations

doFolder provides powerful command-line tools for file system operations:

# Compare two directories with different modes
do-folder compare /path/to/dir1 /path/to/dir2 --compare-mode CONTENT
do-compare /path/to/dir1 /path/to/dir2 --sync --sync-direction A2B
# Calculate file hashes with multiple algorithms
do-folder hash -a sha256,md5 file1.txt file2.txt
do-hash -a blake2b -r /path/to/directory
# Use threading for better performance on large files
do-hash -n 8 -d -r -a sha256 /path/to/large_files/
# Options: -n: number of threads, -d: allow directory, -r: recursive

Advanced Operations

fromdoFolderimportFile, Directory, comparefromdoFolder.hashingimportFileHashCalculator, multipleFileHash# File comparisonfile1=File("version1.txt")
file2=File("version2.txt")
ifcompare.compare(file1, file2):
print("Files are identical")
else:
print("Files differ")
# Directory comparison with detailed difference analysisdir1=Directory("./project_v1")
dir2=Directory("./project_v2")
diff=compare.getDifference(dir1, dir2)
ifdiff:
# Print all differences in flat structurefordindiff.toFlat():
print(f"Difference: {d.path1} vs {d.path2} - {d.diffType}")
# Advanced hashing with caching and multiple algorithmscalculator=FileHashCalculator()
file=File("important_data.txt")
# Single algorithmresult=calculator.get(file, "sha256")
print(f"SHA256: {result.hash}")
# Cached hashing for better performanceprint(f"The second result: {calculator.get(file).hash}")
file.content="New content".encode("utf-8")
# The cache will invalidate when file content changesprint(f"The third result: {calculator.get(file).hash}")
# Multiple algorithms at once (only one disk read is needed)results=calculator.multipleGet(file, ["sha256", "md5", "blake2b"])
foralgo, resultinresults.items():
print(f"{algo.upper()}: {result.hash}")

Path Utilities

Since v2.0.0, doFolder.Path is an alias for Python's built-in pathlib.Path, instead of the custom specialStr.Path from older versions.

For detailed information, please see pathlib documentation.

💻 Command-Line Interface

doFolder provides powerful command-line tools for file system operations with both unified and direct command interfaces.

Installation & Usage

After installing doFolder, you get access to several command-line tools:

# Install doFolder
pip install doFolder
# Direct commands (shortcuts)
do-compare /path1 /path2 # File/directory comparison
do-hash file.txt # File hashing# Unified interface
do-folder compare /path1 /path2 # Same as do-compare
do-folder hash file.txt # Same as do-hash# Python module interface
python -m doFolder compare /path1 /path2
python -m doFolder hash file.txt

Compare Command

Compare files or directories with various options:

# Basic comparison
do-compare file1.txt file2.txt
do-compare /directory1 /directory2
# Different comparison modes
do-compare /dir1 /dir2 --compare-mode CONTENT # Compare file contents
do-compare /dir1 /dir2 --compare-mode SIZE # Compare file sizes
do-compare /dir1 /dir2 --compare-mode TIMETAG # Compare modification times# Synchronization
do-compare /source /backup --sync --sync-direction A2B # Sync A to B
do-compare /dir1 /dir2 --sync --sync-direction BOTH # Bidirectional sync# Overwrite handling
do-compare /dir1 /dir2 --sync --overwrite AUTO # Auto decide by timestamp
do-compare /dir1 /dir2 --sync --overwrite ASK # Ask for each conflict

Hash Command

Calculate file hashes with multiple algorithms and options:

# Basic hashing (uses SHA256 by default)
do-hash file.txt
# Multiple algorithms
do-hash -a sha256,md5,sha1 file.txt
do-hash -a blake2b important_document.txt -a md5,sha1 another_file.txt
# Directory hashing
do-hash -d /directory # Hash all file in directory(no recursion)
do-hash -r -d /project # Recursive directory hashing# Performance options
do-hash -n 8 -d -a sha256,md5,blake2b ./src
# Disable progress display for cleaner output
do-hash --no-progress -r -d /path/to/files
# Path formatting
do-hash -p /absolute/path/file.txt # Use absolute paths
do-hash -f file.txt # Always show full path

Global Options

All commands support these global options:

# Version information
do-folder -v # Show version
do-folder -vv # Show detailed version info# Output control
do-folder --no-color compare /dir1 /dir2 # Disable colored output
do-folder -w 120 hash file.txt # Set console width
do-folder -m hash file.txt # Mute warnings
do-folder -t compare /dir1 /dir2 # Show full traceback on errors

Practical Examples

Backup Verification:

# Compare original and backup, sync differences
do-compare /important/data /backup/data --sync --sync-direction A2B --overwrite AUTO

Development Workflow:

# Compare two versions of a project
do-compare /project/v1 /project/v2 --compare-mode CONTENT
# Hash all source files for change detection
do-hash -a blake2b -r /src --full-path

�🔧 Advanced Features

Command-Line Interface

doFolder provides comprehensive command-line tools with two usage modes:

Unified Interface:

# Main command with subcommands
do-folder compare /path/to/dir1 /path/to/dir2 --sync
do-folder hash -a sha256,md5 file1.txt file2.txt
# Using Python module
python -m doFolder compare /source /backup --compare-mode CONTENT
python -m doFolder hash -a blake2b -r /directory

Direct Commands:

# Direct command shortcuts
do-compare /path/to/dir1 /path/to/dir2 --sync --overwrite AUTO
do-hash -a sha256,md5 file1.txt file2.txt --thread-num 8

Compare Command Features

  • Multiple comparison modes (SIZE, CONTENT, TIMETAG, TIMETAG_AND_SIZE, IGNORE)
  • Directory synchronization with bidirectional support
  • Flexible overwrite policies (A2B, B2A, ASK, AUTO, IGNORE)
  • Relative timestamp formatting
  • Interactive conflict resolution

Hash Command Features

  • Support for multiple hash algorithms (SHA family, MD5, BLAKE2, SHA3, etc.)
  • Multi-threaded processing for performance
  • Recursive directory hashing
  • Progress tracking with detailed status
  • Flexible output formatting

Advanced Hashing System

doFolder includes a sophisticated hashing system with multiple optimization levels:

fromdoFolder.hashingimport (
FileHashCalculator,
ThreadedFileHashCalculator,
ReCalcHashMode,
MemoryFileHashManager
)
fromconcurrent.futuresimportwait# Basic calculator with cachingcalculator=FileHashCalculator(
algorithm="sha256",
useCache=True,
reCalcHashMode=ReCalcHashMode.TIMETAG# Only recalc if file modified
)
# Multi-threaded calculator for better performancewithThreadedFileHashCalculator(threadNum=8) asthreaded_calc:
# Process multiple files concurrentlyfutures= [threaded_calc.threadedGet(file) forfileinfile_list]
wait(futures)
results= [future.result() forfutureinfutures]
# Custom cache managerfromdoFolder.hashingimportLfuMemoryFileHashManagercalculator=FileHashCalculator(
cacheManager=LfuMemoryFileHashManager(maxSize=1000)
)

Error Handling Modes

doFolder provides flexible error handling through UnExistsMode:

fromdoFolderimportFile, UnExistsMode# Different modes for handling non-existent filesfile1=File("missing.txt", unExistsMode=UnExistsMode.ERROR) # Raises exceptionfile2=File("missing.txt", unExistsMode=UnExistsMode.WARN) # Issues warningfile3=File("missing.txt", unExistsMode=UnExistsMode.IGNORE) # Silent handlingfile4=File("missing.txt", unExistsMode=UnExistsMode.CREATE) # Creates if missing

File System Item Types

fromdoFolderimportItemType, createItem# Factory function to create appropriate objectsitem1=createItem("./some_path", ItemType.FILE) # Creates File objectitem2=createItem("./some_path", ItemType.DIR) # Creates Directory objectitem3=createItem("./some_path") # Auto-detects type

🔄 Migration from v1.x.x

doFolder v2.x.x introduces several improvements while maintaining backward compatibility:

  • Enhanced Path Management: Now uses Python's built-in pathlib
  • Renamed Classes: FolderDirectory (backward compatibility maintained)
  • Flexible File Creation: File class can handle directory paths with redirection
  • Improved Type Safety: Full type hints throughout the codebase

Migration Example

# v1.x.x style (still works)fromdoFolderimportFolderfolder=Folder("./my_directory")
# v2.x.x recommended stylefromdoFolderimportDirectorydirectory=Directory("./my_directory")
# Both work identically!

📚 Documentation

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MulanPSL-2.0 License - see the LICENSE file for details.

About

It is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's `pathlib`, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

doFolder

PyPI versionGitHub RepositoryGitHub top languageLicenseDocumentation Status

doFolder is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's pathlib, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

✨ Key Features

  • 🎯 Object-oriented Design: Work with files and directories as Python objects
  • 🌐 Cross-platform Compatibility: Seamlessly works on Windows, macOS, and Linux
  • 🛤️ Advanced Path Handling: Built on Python's pathlib for robust path management
  • 📁 Complete File Operations: Create, move, copy, delete, and modify files and directories
  • 📝 Content Management: Read and write file content with encoding support
  • 🌳 Directory Tree Operations: Navigate and manipulate directory structures
  • 🔍 File Comparison: Compare files and directories with various comparison modes
  • 🔒 Hash Support: Generate and verify file hashes for integrity checking with multi-algorithm support
  • ⚡ High-Performance Hashing: Multi-threaded hash calculation with intelligent caching and progress tracking
  • 🖥️ Command-Line Tools: Comprehensive CLI interface with direct commands (do-compare, do-hash) and unified interface (do-folder)
  • ⚠️ Flexible Error Handling: Comprehensive error modes for different use cases
  • 🏷️ Type Safety: Full type hints for better IDE support and code reliability

📦 Installation

pip install doFolder

Requirements: Python 3.9+

Note: Python 3.8 is no longer supported since version 2.3.0

🚀 Quick Start

Command-Line Quick Start

After installation, you can immediately start using doFolder's command-line tools:

# Compare two directories
do-compare /path/to/source /path/to/backup
# Compare and sync directories
do-compare /path/to/source /path/to/backup --sync --sync-direction A2B
# Calculate file hashes
do-hash file1.txt file2.txt
# Calculate with specific algorithms
do-hash -a sha256,md5 README.md README.zh-cn.md
# Hash all files in a directory recursively
do-hash -r -d /path/to/project
# Use unified interface
do-folder compare /dir1 /dir2 --compare-mode CONTENT
do-folder hash -a blake2b *.py
# Or
python -m doFolder compare /dir1 /dir2 --compare-mode CONTENT
python -m doFolder hash -a blake2b *.py
# Note: do-folder is equal to python -m doFolder, use any of them you like

Python Quick Start

fromdoFolderimportFile, Directory, ItemType# Create directory and file objectsproject_dir=Directory("./my_project")
config_file=project_dir["config.json"]
# Create a new file in the directoryreadme=project_dir.create("README.md", ItemType.FILE)
readme_zh=project_dir.createFile("README.zh-cn.md")
# Write content to the filereadme.content="# My Project\n\nWelcome to my project!".encode("utf-8")
# Create a subdirectorysrc_dir=project_dir.create("src", ItemType.DIR)
# Copy and move filesbackup_config=config_file.copy("./backup/")
config_file.move("./settings/")
# List directory contentsforiteminproject_dir:
print(f"{item.name} ({'Directory'ifitem.isDirelse'File'})")

📖 Usage Examples

Working with Files

fromdoFolderimportFile# Create a file objectfile=File("data.txt")
# Work with binary contentprint(file.content) # Reads content as bytesfile.content="Binary data here".encode("utf-8") # Writes content as bytes# JSON operationsfile.saveAsJson({"name": "John", "age": 30})
data=file.loadAsJson()
# Quickly open filewithfile.open("w", encoding="utf-8") asf:
f.write("Hello, World!")
# File informationprint(f"Size: {file.state.st_size} bytes")
print(f"Modified: {file.state.st_mtime}")
# File hashingprint(f"Hash: {file.hash()}")
print(f"SHA256: {file.hash('sha256')}")
print(f"MD5: {file.hash('md5')}")
# Multi-threaded hashing for better performancefromdoFolder.hashingimportThreadedFileHashCalculatorwithThreadedFileHashCalculator(threadNum=4) ascalculator:
result=calculator.get(file)
print(f"Threaded hash: {result.hash}")

Working with Directories

fromdoFolderimportDirectory, ItemType# Create a directory objectd=Directory("./workspace")
# Create nested directory structured.create("src/utils", ItemType.DIR)
d.create("tests", ItemType.DIR)
d.createDir("docs")
d.createFile("README.md")
# Create filesmain_file=d.create("src/main.py", ItemType.FILE)
test_file=d.create("tests/test_main.py", ItemType.FILE)
# List all items (non-recursive)foritemind:
print(item.path)
# List all items recursivelyforitemind.recursiveTraversal(hideDirectory=False):
print(f"{'📁'ifitem.isDirelse'📄'}{item.path}")
# Find specific sub itemspy_files= ['__init__.py']

Command-Line Operations

doFolder provides powerful command-line tools for file system operations:

# Compare two directories with different modes
do-folder compare /path/to/dir1 /path/to/dir2 --compare-mode CONTENT
do-compare /path/to/dir1 /path/to/dir2 --sync --sync-direction A2B
# Calculate file hashes with multiple algorithms
do-folder hash -a sha256,md5 file1.txt file2.txt
do-hash -a blake2b -r /path/to/directory
# Use threading for better performance on large files
do-hash -n 8 -d -r -a sha256 /path/to/large_files/
# Options: -n: number of threads, -d: allow directory, -r: recursive

Advanced Operations

fromdoFolderimportFile, Directory, comparefromdoFolder.hashingimportFileHashCalculator, multipleFileHash# File comparisonfile1=File("version1.txt")
file2=File("version2.txt")
ifcompare.compare(file1, file2):
print("Files are identical")
else:
print("Files differ")
# Directory comparison with detailed difference analysisdir1=Directory("./project_v1")
dir2=Directory("./project_v2")
diff=compare.getDifference(dir1, dir2)
ifdiff:
# Print all differences in flat structurefordindiff.toFlat():
print(f"Difference: {d.path1} vs {d.path2} - {d.diffType}")
# Advanced hashing with caching and multiple algorithmscalculator=FileHashCalculator()
file=File("important_data.txt")
# Single algorithmresult=calculator.get(file, "sha256")
print(f"SHA256: {result.hash}")
# Cached hashing for better performanceprint(f"The second result: {calculator.get(file).hash}")
file.content="New content".encode("utf-8")
# The cache will invalidate when file content changesprint(f"The third result: {calculator.get(file).hash}")
# Multiple algorithms at once (only one disk read is needed)results=calculator.multipleGet(file, ["sha256", "md5", "blake2b"])
foralgo, resultinresults.items():
print(f"{algo.upper()}: {result.hash}")

Path Utilities

Since v2.0.0, doFolder.Path is an alias for Python's built-in pathlib.Path, instead of the custom specialStr.Path from older versions.

For detailed information, please see pathlib documentation.

💻 Command-Line Interface

doFolder provides powerful command-line tools for file system operations with both unified and direct command interfaces.

Installation & Usage

After installing doFolder, you get access to several command-line tools:

# Install doFolder
pip install doFolder
# Direct commands (shortcuts)
do-compare /path1 /path2 # File/directory comparison
do-hash file.txt # File hashing# Unified interface
do-folder compare /path1 /path2 # Same as do-compare
do-folder hash file.txt # Same as do-hash# Python module interface
python -m doFolder compare /path1 /path2
python -m doFolder hash file.txt

Compare Command

Compare files or directories with various options:

# Basic comparison
do-compare file1.txt file2.txt
do-compare /directory1 /directory2
# Different comparison modes
do-compare /dir1 /dir2 --compare-mode CONTENT # Compare file contents
do-compare /dir1 /dir2 --compare-mode SIZE # Compare file sizes
do-compare /dir1 /dir2 --compare-mode TIMETAG # Compare modification times# Synchronization
do-compare /source /backup --sync --sync-direction A2B # Sync A to B
do-compare /dir1 /dir2 --sync --sync-direction BOTH # Bidirectional sync# Overwrite handling
do-compare /dir1 /dir2 --sync --overwrite AUTO # Auto decide by timestamp
do-compare /dir1 /dir2 --sync --overwrite ASK # Ask for each conflict

Hash Command

Calculate file hashes with multiple algorithms and options:

# Basic hashing (uses SHA256 by default)
do-hash file.txt
# Multiple algorithms
do-hash -a sha256,md5,sha1 file.txt
do-hash -a blake2b important_document.txt -a md5,sha1 another_file.txt
# Directory hashing
do-hash -d /directory # Hash all file in directory(no recursion)
do-hash -r -d /project # Recursive directory hashing# Performance options
do-hash -n 8 -d -a sha256,md5,blake2b ./src
# Disable progress display for cleaner output
do-hash --no-progress -r -d /path/to/files
# Path formatting
do-hash -p /absolute/path/file.txt # Use absolute paths
do-hash -f file.txt # Always show full path

Global Options

All commands support these global options:

# Version information
do-folder -v # Show version
do-folder -vv # Show detailed version info# Output control
do-folder --no-color compare /dir1 /dir2 # Disable colored output
do-folder -w 120 hash file.txt # Set console width
do-folder -m hash file.txt # Mute warnings
do-folder -t compare /dir1 /dir2 # Show full traceback on errors

Practical Examples

Backup Verification:

# Compare original and backup, sync differences
do-compare /important/data /backup/data --sync --sync-direction A2B --overwrite AUTO

Development Workflow:

# Compare two versions of a project
do-compare /project/v1 /project/v2 --compare-mode CONTENT
# Hash all source files for change detection
do-hash -a blake2b -r /src --full-path

�🔧 Advanced Features

Command-Line Interface

doFolder provides comprehensive command-line tools with two usage modes:

Unified Interface:

# Main command with subcommands
do-folder compare /path/to/dir1 /path/to/dir2 --sync
do-folder hash -a sha256,md5 file1.txt file2.txt
# Using Python module
python -m doFolder compare /source /backup --compare-mode CONTENT
python -m doFolder hash -a blake2b -r /directory

Direct Commands:

# Direct command shortcuts
do-compare /path/to/dir1 /path/to/dir2 --sync --overwrite AUTO
do-hash -a sha256,md5 file1.txt file2.txt --thread-num 8

Compare Command Features

  • Multiple comparison modes (SIZE, CONTENT, TIMETAG, TIMETAG_AND_SIZE, IGNORE)
  • Directory synchronization with bidirectional support
  • Flexible overwrite policies (A2B, B2A, ASK, AUTO, IGNORE)
  • Relative timestamp formatting
  • Interactive conflict resolution

Hash Command Features

  • Support for multiple hash algorithms (SHA family, MD5, BLAKE2, SHA3, etc.)
  • Multi-threaded processing for performance
  • Recursive directory hashing
  • Progress tracking with detailed status
  • Flexible output formatting

Advanced Hashing System

doFolder includes a sophisticated hashing system with multiple optimization levels:

fromdoFolder.hashingimport (
FileHashCalculator,
ThreadedFileHashCalculator,
ReCalcHashMode,
MemoryFileHashManager
)
fromconcurrent.futuresimportwait# Basic calculator with cachingcalculator=FileHashCalculator(
algorithm="sha256",
useCache=True,
reCalcHashMode=ReCalcHashMode.TIMETAG# Only recalc if file modified
)
# Multi-threaded calculator for better performancewithThreadedFileHashCalculator(threadNum=8) asthreaded_calc:
# Process multiple files concurrentlyfutures= [threaded_calc.threadedGet(file) forfileinfile_list]
wait(futures)
results= [future.result() forfutureinfutures]
# Custom cache managerfromdoFolder.hashingimportLfuMemoryFileHashManagercalculator=FileHashCalculator(
cacheManager=LfuMemoryFileHashManager(maxSize=1000)
)

Error Handling Modes

doFolder provides flexible error handling through UnExistsMode:

fromdoFolderimportFile, UnExistsMode# Different modes for handling non-existent filesfile1=File("missing.txt", unExistsMode=UnExistsMode.ERROR) # Raises exceptionfile2=File("missing.txt", unExistsMode=UnExistsMode.WARN) # Issues warningfile3=File("missing.txt", unExistsMode=UnExistsMode.IGNORE) # Silent handlingfile4=File("missing.txt", unExistsMode=UnExistsMode.CREATE) # Creates if missing

File System Item Types

fromdoFolderimportItemType, createItem# Factory function to create appropriate objectsitem1=createItem("./some_path", ItemType.FILE) # Creates File objectitem2=createItem("./some_path", ItemType.DIR) # Creates Directory objectitem3=createItem("./some_path") # Auto-detects type

🔄 Migration from v1.x.x

doFolder v2.x.x introduces several improvements while maintaining backward compatibility:

  • Enhanced Path Management: Now uses Python's built-in pathlib
  • Renamed Classes: FolderDirectory (backward compatibility maintained)
  • Flexible File Creation: File class can handle directory paths with redirection
  • Improved Type Safety: Full type hints throughout the codebase

Migration Example

# v1.x.x style (still works)fromdoFolderimportFolderfolder=Folder("./my_directory")
# v2.x.x recommended stylefromdoFolderimportDirectorydirectory=Directory("./my_directory")
# Both work identically!

📚 Documentation

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MulanPSL-2.0 License - see the LICENSE file for details.

About

It is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's `pathlib`, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

doFolder

PyPI versionGitHub RepositoryGitHub top languageLicenseDocumentation Status

doFolder is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's pathlib, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

✨ Key Features

  • 🎯 Object-oriented Design: Work with files and directories as Python objects
  • 🌐 Cross-platform Compatibility: Seamlessly works on Windows, macOS, and Linux
  • 🛤️ Advanced Path Handling: Built on Python's pathlib for robust path management
  • 📁 Complete File Operations: Create, move, copy, delete, and modify files and directories
  • 📝 Content Management: Read and write file content with encoding support
  • 🌳 Directory Tree Operations: Navigate and manipulate directory structures
  • 🔍 File Comparison: Compare files and directories with various comparison modes
  • 🔒 Hash Support: Generate and verify file hashes for integrity checking with multi-algorithm support
  • ⚡ High-Performance Hashing: Multi-threaded hash calculation with intelligent caching and progress tracking
  • 🖥️ Command-Line Tools: Comprehensive CLI interface with direct commands (do-compare, do-hash) and unified interface (do-folder)
  • ⚠️ Flexible Error Handling: Comprehensive error modes for different use cases
  • 🏷️ Type Safety: Full type hints for better IDE support and code reliability

📦 Installation

pip install doFolder

Requirements: Python 3.9+

Note: Python 3.8 is no longer supported since version 2.3.0

🚀 Quick Start

Command-Line Quick Start

After installation, you can immediately start using doFolder's command-line tools:

# Compare two directories
do-compare /path/to/source /path/to/backup
# Compare and sync directories
do-compare /path/to/source /path/to/backup --sync --sync-direction A2B
# Calculate file hashes
do-hash file1.txt file2.txt
# Calculate with specific algorithms
do-hash -a sha256,md5 README.md README.zh-cn.md
# Hash all files in a directory recursively
do-hash -r -d /path/to/project
# Use unified interface
do-folder compare /dir1 /dir2 --compare-mode CONTENT
do-folder hash -a blake2b *.py
# Or
python -m doFolder compare /dir1 /dir2 --compare-mode CONTENT
python -m doFolder hash -a blake2b *.py
# Note: do-folder is equal to python -m doFolder, use any of them you like

Python Quick Start

fromdoFolderimportFile, Directory, ItemType# Create directory and file objectsproject_dir=Directory("./my_project")
config_file=project_dir["config.json"]
# Create a new file in the directoryreadme=project_dir.create("README.md", ItemType.FILE)
readme_zh=project_dir.createFile("README.zh-cn.md")
# Write content to the filereadme.content="# My Project\n\nWelcome to my project!".encode("utf-8")
# Create a subdirectorysrc_dir=project_dir.create("src", ItemType.DIR)
# Copy and move filesbackup_config=config_file.copy("./backup/")
config_file.move("./settings/")
# List directory contentsforiteminproject_dir:
print(f"{item.name} ({'Directory'ifitem.isDirelse'File'})")

📖 Usage Examples

Working with Files

fromdoFolderimportFile# Create a file objectfile=File("data.txt")
# Work with binary contentprint(file.content) # Reads content as bytesfile.content="Binary data here".encode("utf-8") # Writes content as bytes# JSON operationsfile.saveAsJson({"name": "John", "age": 30})
data=file.loadAsJson()
# Quickly open filewithfile.open("w", encoding="utf-8") asf:
f.write("Hello, World!")
# File informationprint(f"Size: {file.state.st_size} bytes")
print(f"Modified: {file.state.st_mtime}")
# File hashingprint(f"Hash: {file.hash()}")
print(f"SHA256: {file.hash('sha256')}")
print(f"MD5: {file.hash('md5')}")
# Multi-threaded hashing for better performancefromdoFolder.hashingimportThreadedFileHashCalculatorwithThreadedFileHashCalculator(threadNum=4) ascalculator:
result=calculator.get(file)
print(f"Threaded hash: {result.hash}")

Working with Directories

fromdoFolderimportDirectory, ItemType# Create a directory objectd=Directory("./workspace")
# Create nested directory structured.create("src/utils", ItemType.DIR)
d.create("tests", ItemType.DIR)
d.createDir("docs")
d.createFile("README.md")
# Create filesmain_file=d.create("src/main.py", ItemType.FILE)
test_file=d.create("tests/test_main.py", ItemType.FILE)
# List all items (non-recursive)foritemind:
print(item.path)
# List all items recursivelyforitemind.recursiveTraversal(hideDirectory=False):
print(f"{'📁'ifitem.isDirelse'📄'}{item.path}")
# Find specific sub itemspy_files= ['__init__.py']

Command-Line Operations

doFolder provides powerful command-line tools for file system operations:

# Compare two directories with different modes
do-folder compare /path/to/dir1 /path/to/dir2 --compare-mode CONTENT
do-compare /path/to/dir1 /path/to/dir2 --sync --sync-direction A2B
# Calculate file hashes with multiple algorithms
do-folder hash -a sha256,md5 file1.txt file2.txt
do-hash -a blake2b -r /path/to/directory
# Use threading for better performance on large files
do-hash -n 8 -d -r -a sha256 /path/to/large_files/
# Options: -n: number of threads, -d: allow directory, -r: recursive

Advanced Operations

fromdoFolderimportFile, Directory, comparefromdoFolder.hashingimportFileHashCalculator, multipleFileHash# File comparisonfile1=File("version1.txt")
file2=File("version2.txt")
ifcompare.compare(file1, file2):
print("Files are identical")
else:
print("Files differ")
# Directory comparison with detailed difference analysisdir1=Directory("./project_v1")
dir2=Directory("./project_v2")
diff=compare.getDifference(dir1, dir2)
ifdiff:
# Print all differences in flat structurefordindiff.toFlat():
print(f"Difference: {d.path1} vs {d.path2} - {d.diffType}")
# Advanced hashing with caching and multiple algorithmscalculator=FileHashCalculator()
file=File("important_data.txt")
# Single algorithmresult=calculator.get(file, "sha256")
print(f"SHA256: {result.hash}")
# Cached hashing for better performanceprint(f"The second result: {calculator.get(file).hash}")
file.content="New content".encode("utf-8")
# The cache will invalidate when file content changesprint(f"The third result: {calculator.get(file).hash}")
# Multiple algorithms at once (only one disk read is needed)results=calculator.multipleGet(file, ["sha256", "md5", "blake2b"])
foralgo, resultinresults.items():
print(f"{algo.upper()}: {result.hash}")

Path Utilities

Since v2.0.0, doFolder.Path is an alias for Python's built-in pathlib.Path, instead of the custom specialStr.Path from older versions.

For detailed information, please see pathlib documentation.

💻 Command-Line Interface

doFolder provides powerful command-line tools for file system operations with both unified and direct command interfaces.

Installation & Usage

After installing doFolder, you get access to several command-line tools:

# Install doFolder
pip install doFolder
# Direct commands (shortcuts)
do-compare /path1 /path2 # File/directory comparison
do-hash file.txt # File hashing# Unified interface
do-folder compare /path1 /path2 # Same as do-compare
do-folder hash file.txt # Same as do-hash# Python module interface
python -m doFolder compare /path1 /path2
python -m doFolder hash file.txt

Compare Command

Compare files or directories with various options:

# Basic comparison
do-compare file1.txt file2.txt
do-compare /directory1 /directory2
# Different comparison modes
do-compare /dir1 /dir2 --compare-mode CONTENT # Compare file contents
do-compare /dir1 /dir2 --compare-mode SIZE # Compare file sizes
do-compare /dir1 /dir2 --compare-mode TIMETAG # Compare modification times# Synchronization
do-compare /source /backup --sync --sync-direction A2B # Sync A to B
do-compare /dir1 /dir2 --sync --sync-direction BOTH # Bidirectional sync# Overwrite handling
do-compare /dir1 /dir2 --sync --overwrite AUTO # Auto decide by timestamp
do-compare /dir1 /dir2 --sync --overwrite ASK # Ask for each conflict

Hash Command

Calculate file hashes with multiple algorithms and options:

# Basic hashing (uses SHA256 by default)
do-hash file.txt
# Multiple algorithms
do-hash -a sha256,md5,sha1 file.txt
do-hash -a blake2b important_document.txt -a md5,sha1 another_file.txt
# Directory hashing
do-hash -d /directory # Hash all file in directory(no recursion)
do-hash -r -d /project # Recursive directory hashing# Performance options
do-hash -n 8 -d -a sha256,md5,blake2b ./src
# Disable progress display for cleaner output
do-hash --no-progress -r -d /path/to/files
# Path formatting
do-hash -p /absolute/path/file.txt # Use absolute paths
do-hash -f file.txt # Always show full path

Global Options

All commands support these global options:

# Version information
do-folder -v # Show version
do-folder -vv # Show detailed version info# Output control
do-folder --no-color compare /dir1 /dir2 # Disable colored output
do-folder -w 120 hash file.txt # Set console width
do-folder -m hash file.txt # Mute warnings
do-folder -t compare /dir1 /dir2 # Show full traceback on errors

Practical Examples

Backup Verification:

# Compare original and backup, sync differences
do-compare /important/data /backup/data --sync --sync-direction A2B --overwrite AUTO

Development Workflow:

# Compare two versions of a project
do-compare /project/v1 /project/v2 --compare-mode CONTENT
# Hash all source files for change detection
do-hash -a blake2b -r /src --full-path

�🔧 Advanced Features

Command-Line Interface

doFolder provides comprehensive command-line tools with two usage modes:

Unified Interface:

# Main command with subcommands
do-folder compare /path/to/dir1 /path/to/dir2 --sync
do-folder hash -a sha256,md5 file1.txt file2.txt
# Using Python module
python -m doFolder compare /source /backup --compare-mode CONTENT
python -m doFolder hash -a blake2b -r /directory

Direct Commands:

# Direct command shortcuts
do-compare /path/to/dir1 /path/to/dir2 --sync --overwrite AUTO
do-hash -a sha256,md5 file1.txt file2.txt --thread-num 8

Compare Command Features

  • Multiple comparison modes (SIZE, CONTENT, TIMETAG, TIMETAG_AND_SIZE, IGNORE)
  • Directory synchronization with bidirectional support
  • Flexible overwrite policies (A2B, B2A, ASK, AUTO, IGNORE)
  • Relative timestamp formatting
  • Interactive conflict resolution

Hash Command Features

  • Support for multiple hash algorithms (SHA family, MD5, BLAKE2, SHA3, etc.)
  • Multi-threaded processing for performance
  • Recursive directory hashing
  • Progress tracking with detailed status
  • Flexible output formatting

Advanced Hashing System

doFolder includes a sophisticated hashing system with multiple optimization levels:

fromdoFolder.hashingimport (
FileHashCalculator,
ThreadedFileHashCalculator,
ReCalcHashMode,
MemoryFileHashManager
)
fromconcurrent.futuresimportwait# Basic calculator with cachingcalculator=FileHashCalculator(
algorithm="sha256",
useCache=True,
reCalcHashMode=ReCalcHashMode.TIMETAG# Only recalc if file modified
)
# Multi-threaded calculator for better performancewithThreadedFileHashCalculator(threadNum=8) asthreaded_calc:
# Process multiple files concurrentlyfutures= [threaded_calc.threadedGet(file) forfileinfile_list]
wait(futures)
results= [future.result() forfutureinfutures]
# Custom cache managerfromdoFolder.hashingimportLfuMemoryFileHashManagercalculator=FileHashCalculator(
cacheManager=LfuMemoryFileHashManager(maxSize=1000)
)

Error Handling Modes

doFolder provides flexible error handling through UnExistsMode:

fromdoFolderimportFile, UnExistsMode# Different modes for handling non-existent filesfile1=File("missing.txt", unExistsMode=UnExistsMode.ERROR) # Raises exceptionfile2=File("missing.txt", unExistsMode=UnExistsMode.WARN) # Issues warningfile3=File("missing.txt", unExistsMode=UnExistsMode.IGNORE) # Silent handlingfile4=File("missing.txt", unExistsMode=UnExistsMode.CREATE) # Creates if missing

File System Item Types

fromdoFolderimportItemType, createItem# Factory function to create appropriate objectsitem1=createItem("./some_path", ItemType.FILE) # Creates File objectitem2=createItem("./some_path", ItemType.DIR) # Creates Directory objectitem3=createItem("./some_path") # Auto-detects type

🔄 Migration from v1.x.x

doFolder v2.x.x introduces several improvements while maintaining backward compatibility:

  • Enhanced Path Management: Now uses Python's built-in pathlib
  • Renamed Classes: FolderDirectory (backward compatibility maintained)
  • Flexible File Creation: File class can handle directory paths with redirection
  • Improved Type Safety: Full type hints throughout the codebase

Migration Example

# v1.x.x style (still works)fromdoFolderimportFolderfolder=Folder("./my_directory")
# v2.x.x recommended stylefromdoFolderimportDirectorydirectory=Directory("./my_directory")
# Both work identically!

📚 Documentation

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MulanPSL-2.0 License - see the LICENSE file for details.

About

It is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's `pathlib`, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

doFolder

PyPI versionGitHub RepositoryGitHub top languageLicenseDocumentation Status

doFolder is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's pathlib, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

✨ Key Features

  • 🎯 Object-oriented Design: Work with files and directories as Python objects
  • 🌐 Cross-platform Compatibility: Seamlessly works on Windows, macOS, and Linux
  • 🛤️ Advanced Path Handling: Built on Python's pathlib for robust path management
  • 📁 Complete File Operations: Create, move, copy, delete, and modify files and directories
  • 📝 Content Management: Read and write file content with encoding support
  • 🌳 Directory Tree Operations: Navigate and manipulate directory structures
  • 🔍 File Comparison: Compare files and directories with various comparison modes
  • 🔒 Hash Support: Generate and verify file hashes for integrity checking with multi-algorithm support
  • ⚡ High-Performance Hashing: Multi-threaded hash calculation with intelligent caching and progress tracking
  • 🖥️ Command-Line Tools: Comprehensive CLI interface with direct commands (do-compare, do-hash) and unified interface (do-folder)
  • ⚠️ Flexible Error Handling: Comprehensive error modes for different use cases
  • 🏷️ Type Safety: Full type hints for better IDE support and code reliability

📦 Installation

pip install doFolder

Requirements: Python 3.9+

Note: Python 3.8 is no longer supported since version 2.3.0

🚀 Quick Start

Command-Line Quick Start

After installation, you can immediately start using doFolder's command-line tools:

# Compare two directories
do-compare /path/to/source /path/to/backup
# Compare and sync directories
do-compare /path/to/source /path/to/backup --sync --sync-direction A2B
# Calculate file hashes
do-hash file1.txt file2.txt
# Calculate with specific algorithms
do-hash -a sha256,md5 README.md README.zh-cn.md
# Hash all files in a directory recursively
do-hash -r -d /path/to/project
# Use unified interface
do-folder compare /dir1 /dir2 --compare-mode CONTENT
do-folder hash -a blake2b *.py
# Or
python -m doFolder compare /dir1 /dir2 --compare-mode CONTENT
python -m doFolder hash -a blake2b *.py
# Note: do-folder is equal to python -m doFolder, use any of them you like

Python Quick Start

fromdoFolderimportFile, Directory, ItemType# Create directory and file objectsproject_dir=Directory("./my_project")
config_file=project_dir["config.json"]
# Create a new file in the directoryreadme=project_dir.create("README.md", ItemType.FILE)
readme_zh=project_dir.createFile("README.zh-cn.md")
# Write content to the filereadme.content="# My Project\n\nWelcome to my project!".encode("utf-8")
# Create a subdirectorysrc_dir=project_dir.create("src", ItemType.DIR)
# Copy and move filesbackup_config=config_file.copy("./backup/")
config_file.move("./settings/")
# List directory contentsforiteminproject_dir:
print(f"{item.name} ({'Directory'ifitem.isDirelse'File'})")

📖 Usage Examples

Working with Files

fromdoFolderimportFile# Create a file objectfile=File("data.txt")
# Work with binary contentprint(file.content) # Reads content as bytesfile.content="Binary data here".encode("utf-8") # Writes content as bytes# JSON operationsfile.saveAsJson({"name": "John", "age": 30})
data=file.loadAsJson()
# Quickly open filewithfile.open("w", encoding="utf-8") asf:
f.write("Hello, World!")
# File informationprint(f"Size: {file.state.st_size} bytes")
print(f"Modified: {file.state.st_mtime}")
# File hashingprint(f"Hash: {file.hash()}")
print(f"SHA256: {file.hash('sha256')}")
print(f"MD5: {file.hash('md5')}")
# Multi-threaded hashing for better performancefromdoFolder.hashingimportThreadedFileHashCalculatorwithThreadedFileHashCalculator(threadNum=4) ascalculator:
result=calculator.get(file)
print(f"Threaded hash: {result.hash}")

Working with Directories

fromdoFolderimportDirectory, ItemType# Create a directory objectd=Directory("./workspace")
# Create nested directory structured.create("src/utils", ItemType.DIR)
d.create("tests", ItemType.DIR)
d.createDir("docs")
d.createFile("README.md")
# Create filesmain_file=d.create("src/main.py", ItemType.FILE)
test_file=d.create("tests/test_main.py", ItemType.FILE)
# List all items (non-recursive)foritemind:
print(item.path)
# List all items recursivelyforitemind.recursiveTraversal(hideDirectory=False):
print(f"{'📁'ifitem.isDirelse'📄'}{item.path}")
# Find specific sub itemspy_files= ['__init__.py']

Command-Line Operations

doFolder provides powerful command-line tools for file system operations:

# Compare two directories with different modes
do-folder compare /path/to/dir1 /path/to/dir2 --compare-mode CONTENT
do-compare /path/to/dir1 /path/to/dir2 --sync --sync-direction A2B
# Calculate file hashes with multiple algorithms
do-folder hash -a sha256,md5 file1.txt file2.txt
do-hash -a blake2b -r /path/to/directory
# Use threading for better performance on large files
do-hash -n 8 -d -r -a sha256 /path/to/large_files/
# Options: -n: number of threads, -d: allow directory, -r: recursive

Advanced Operations

fromdoFolderimportFile, Directory, comparefromdoFolder.hashingimportFileHashCalculator, multipleFileHash# File comparisonfile1=File("version1.txt")
file2=File("version2.txt")
ifcompare.compare(file1, file2):
print("Files are identical")
else:
print("Files differ")
# Directory comparison with detailed difference analysisdir1=Directory("./project_v1")
dir2=Directory("./project_v2")
diff=compare.getDifference(dir1, dir2)
ifdiff:
# Print all differences in flat structurefordindiff.toFlat():
print(f"Difference: {d.path1} vs {d.path2} - {d.diffType}")
# Advanced hashing with caching and multiple algorithmscalculator=FileHashCalculator()
file=File("important_data.txt")
# Single algorithmresult=calculator.get(file, "sha256")
print(f"SHA256: {result.hash}")
# Cached hashing for better performanceprint(f"The second result: {calculator.get(file).hash}")
file.content="New content".encode("utf-8")
# The cache will invalidate when file content changesprint(f"The third result: {calculator.get(file).hash}")
# Multiple algorithms at once (only one disk read is needed)results=calculator.multipleGet(file, ["sha256", "md5", "blake2b"])
foralgo, resultinresults.items():
print(f"{algo.upper()}: {result.hash}")

Path Utilities

Since v2.0.0, doFolder.Path is an alias for Python's built-in pathlib.Path, instead of the custom specialStr.Path from older versions.

For detailed information, please see pathlib documentation.

💻 Command-Line Interface

doFolder provides powerful command-line tools for file system operations with both unified and direct command interfaces.

Installation & Usage

After installing doFolder, you get access to several command-line tools:

# Install doFolder
pip install doFolder
# Direct commands (shortcuts)
do-compare /path1 /path2 # File/directory comparison
do-hash file.txt # File hashing# Unified interface
do-folder compare /path1 /path2 # Same as do-compare
do-folder hash file.txt # Same as do-hash# Python module interface
python -m doFolder compare /path1 /path2
python -m doFolder hash file.txt

Compare Command

Compare files or directories with various options:

# Basic comparison
do-compare file1.txt file2.txt
do-compare /directory1 /directory2
# Different comparison modes
do-compare /dir1 /dir2 --compare-mode CONTENT # Compare file contents
do-compare /dir1 /dir2 --compare-mode SIZE # Compare file sizes
do-compare /dir1 /dir2 --compare-mode TIMETAG # Compare modification times# Synchronization
do-compare /source /backup --sync --sync-direction A2B # Sync A to B
do-compare /dir1 /dir2 --sync --sync-direction BOTH # Bidirectional sync# Overwrite handling
do-compare /dir1 /dir2 --sync --overwrite AUTO # Auto decide by timestamp
do-compare /dir1 /dir2 --sync --overwrite ASK # Ask for each conflict

Hash Command

Calculate file hashes with multiple algorithms and options:

# Basic hashing (uses SHA256 by default)
do-hash file.txt
# Multiple algorithms
do-hash -a sha256,md5,sha1 file.txt
do-hash -a blake2b important_document.txt -a md5,sha1 another_file.txt
# Directory hashing
do-hash -d /directory # Hash all file in directory(no recursion)
do-hash -r -d /project # Recursive directory hashing# Performance options
do-hash -n 8 -d -a sha256,md5,blake2b ./src
# Disable progress display for cleaner output
do-hash --no-progress -r -d /path/to/files
# Path formatting
do-hash -p /absolute/path/file.txt # Use absolute paths
do-hash -f file.txt # Always show full path

Global Options

All commands support these global options:

# Version information
do-folder -v # Show version
do-folder -vv # Show detailed version info# Output control
do-folder --no-color compare /dir1 /dir2 # Disable colored output
do-folder -w 120 hash file.txt # Set console width
do-folder -m hash file.txt # Mute warnings
do-folder -t compare /dir1 /dir2 # Show full traceback on errors

Practical Examples

Backup Verification:

# Compare original and backup, sync differences
do-compare /important/data /backup/data --sync --sync-direction A2B --overwrite AUTO

Development Workflow:

# Compare two versions of a project
do-compare /project/v1 /project/v2 --compare-mode CONTENT
# Hash all source files for change detection
do-hash -a blake2b -r /src --full-path

�🔧 Advanced Features

Command-Line Interface

doFolder provides comprehensive command-line tools with two usage modes:

Unified Interface:

# Main command with subcommands
do-folder compare /path/to/dir1 /path/to/dir2 --sync
do-folder hash -a sha256,md5 file1.txt file2.txt
# Using Python module
python -m doFolder compare /source /backup --compare-mode CONTENT
python -m doFolder hash -a blake2b -r /directory

Direct Commands:

# Direct command shortcuts
do-compare /path/to/dir1 /path/to/dir2 --sync --overwrite AUTO
do-hash -a sha256,md5 file1.txt file2.txt --thread-num 8

Compare Command Features

  • Multiple comparison modes (SIZE, CONTENT, TIMETAG, TIMETAG_AND_SIZE, IGNORE)
  • Directory synchronization with bidirectional support
  • Flexible overwrite policies (A2B, B2A, ASK, AUTO, IGNORE)
  • Relative timestamp formatting
  • Interactive conflict resolution

Hash Command Features

  • Support for multiple hash algorithms (SHA family, MD5, BLAKE2, SHA3, etc.)
  • Multi-threaded processing for performance
  • Recursive directory hashing
  • Progress tracking with detailed status
  • Flexible output formatting

Advanced Hashing System

doFolder includes a sophisticated hashing system with multiple optimization levels:

fromdoFolder.hashingimport (
FileHashCalculator,
ThreadedFileHashCalculator,
ReCalcHashMode,
MemoryFileHashManager
)
fromconcurrent.futuresimportwait# Basic calculator with cachingcalculator=FileHashCalculator(
algorithm="sha256",
useCache=True,
reCalcHashMode=ReCalcHashMode.TIMETAG# Only recalc if file modified
)
# Multi-threaded calculator for better performancewithThreadedFileHashCalculator(threadNum=8) asthreaded_calc:
# Process multiple files concurrentlyfutures= [threaded_calc.threadedGet(file) forfileinfile_list]
wait(futures)
results= [future.result() forfutureinfutures]
# Custom cache managerfromdoFolder.hashingimportLfuMemoryFileHashManagercalculator=FileHashCalculator(
cacheManager=LfuMemoryFileHashManager(maxSize=1000)
)

Error Handling Modes

doFolder provides flexible error handling through UnExistsMode:

fromdoFolderimportFile, UnExistsMode# Different modes for handling non-existent filesfile1=File("missing.txt", unExistsMode=UnExistsMode.ERROR) # Raises exceptionfile2=File("missing.txt", unExistsMode=UnExistsMode.WARN) # Issues warningfile3=File("missing.txt", unExistsMode=UnExistsMode.IGNORE) # Silent handlingfile4=File("missing.txt", unExistsMode=UnExistsMode.CREATE) # Creates if missing

File System Item Types

fromdoFolderimportItemType, createItem# Factory function to create appropriate objectsitem1=createItem("./some_path", ItemType.FILE) # Creates File objectitem2=createItem("./some_path", ItemType.DIR) # Creates Directory objectitem3=createItem("./some_path") # Auto-detects type

🔄 Migration from v1.x.x

doFolder v2.x.x introduces several improvements while maintaining backward compatibility:

  • Enhanced Path Management: Now uses Python's built-in pathlib
  • Renamed Classes: FolderDirectory (backward compatibility maintained)
  • Flexible File Creation: File class can handle directory paths with redirection
  • Improved Type Safety: Full type hints throughout the codebase

Migration Example

# v1.x.x style (still works)fromdoFolderimportFolderfolder=Folder("./my_directory")
# v2.x.x recommended stylefromdoFolderimportDirectorydirectory=Directory("./my_directory")
# Both work identically!

📚 Documentation

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MulanPSL-2.0 License - see the LICENSE file for details.

About

It is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's `pathlib`, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

doFolder

PyPI versionGitHub RepositoryGitHub top languageLicenseDocumentation Status

doFolder is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's pathlib, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

✨ Key Features

  • 🎯 Object-oriented Design: Work with files and directories as Python objects
  • 🌐 Cross-platform Compatibility: Seamlessly works on Windows, macOS, and Linux
  • 🛤️ Advanced Path Handling: Built on Python's pathlib for robust path management
  • 📁 Complete File Operations: Create, move, copy, delete, and modify files and directories
  • 📝 Content Management: Read and write file content with encoding support
  • 🌳 Directory Tree Operations: Navigate and manipulate directory structures
  • 🔍 File Comparison: Compare files and directories with various comparison modes
  • 🔒 Hash Support: Generate and verify file hashes for integrity checking with multi-algorithm support
  • ⚡ High-Performance Hashing: Multi-threaded hash calculation with intelligent caching and progress tracking
  • 🖥️ Command-Line Tools: Comprehensive CLI interface with direct commands (do-compare, do-hash) and unified interface (do-folder)
  • ⚠️ Flexible Error Handling: Comprehensive error modes for different use cases
  • 🏷️ Type Safety: Full type hints for better IDE support and code reliability

📦 Installation

pip install doFolder

Requirements: Python 3.9+

Note: Python 3.8 is no longer supported since version 2.3.0

🚀 Quick Start

Command-Line Quick Start

After installation, you can immediately start using doFolder's command-line tools:

# Compare two directories
do-compare /path/to/source /path/to/backup
# Compare and sync directories
do-compare /path/to/source /path/to/backup --sync --sync-direction A2B
# Calculate file hashes
do-hash file1.txt file2.txt
# Calculate with specific algorithms
do-hash -a sha256,md5 README.md README.zh-cn.md
# Hash all files in a directory recursively
do-hash -r -d /path/to/project
# Use unified interface
do-folder compare /dir1 /dir2 --compare-mode CONTENT
do-folder hash -a blake2b *.py
# Or
python -m doFolder compare /dir1 /dir2 --compare-mode CONTENT
python -m doFolder hash -a blake2b *.py
# Note: do-folder is equal to python -m doFolder, use any of them you like

Python Quick Start

fromdoFolderimportFile, Directory, ItemType# Create directory and file objectsproject_dir=Directory("./my_project")
config_file=project_dir["config.json"]
# Create a new file in the directoryreadme=project_dir.create("README.md", ItemType.FILE)
readme_zh=project_dir.createFile("README.zh-cn.md")
# Write content to the filereadme.content="# My Project\n\nWelcome to my project!".encode("utf-8")
# Create a subdirectorysrc_dir=project_dir.create("src", ItemType.DIR)
# Copy and move filesbackup_config=config_file.copy("./backup/")
config_file.move("./settings/")
# List directory contentsforiteminproject_dir:
print(f"{item.name} ({'Directory'ifitem.isDirelse'File'})")

📖 Usage Examples

Working with Files

fromdoFolderimportFile# Create a file objectfile=File("data.txt")
# Work with binary contentprint(file.content) # Reads content as bytesfile.content="Binary data here".encode("utf-8") # Writes content as bytes# JSON operationsfile.saveAsJson({"name": "John", "age": 30})
data=file.loadAsJson()
# Quickly open filewithfile.open("w", encoding="utf-8") asf:
f.write("Hello, World!")
# File informationprint(f"Size: {file.state.st_size} bytes")
print(f"Modified: {file.state.st_mtime}")
# File hashingprint(f"Hash: {file.hash()}")
print(f"SHA256: {file.hash('sha256')}")
print(f"MD5: {file.hash('md5')}")
# Multi-threaded hashing for better performancefromdoFolder.hashingimportThreadedFileHashCalculatorwithThreadedFileHashCalculator(threadNum=4) ascalculator:
result=calculator.get(file)
print(f"Threaded hash: {result.hash}")

Working with Directories

fromdoFolderimportDirectory, ItemType# Create a directory objectd=Directory("./workspace")
# Create nested directory structured.create("src/utils", ItemType.DIR)
d.create("tests", ItemType.DIR)
d.createDir("docs")
d.createFile("README.md")
# Create filesmain_file=d.create("src/main.py", ItemType.FILE)
test_file=d.create("tests/test_main.py", ItemType.FILE)
# List all items (non-recursive)foritemind:
print(item.path)
# List all items recursivelyforitemind.recursiveTraversal(hideDirectory=False):
print(f"{'📁'ifitem.isDirelse'📄'}{item.path}")
# Find specific sub itemspy_files= ['__init__.py']

Command-Line Operations

doFolder provides powerful command-line tools for file system operations:

# Compare two directories with different modes
do-folder compare /path/to/dir1 /path/to/dir2 --compare-mode CONTENT
do-compare /path/to/dir1 /path/to/dir2 --sync --sync-direction A2B
# Calculate file hashes with multiple algorithms
do-folder hash -a sha256,md5 file1.txt file2.txt
do-hash -a blake2b -r /path/to/directory
# Use threading for better performance on large files
do-hash -n 8 -d -r -a sha256 /path/to/large_files/
# Options: -n: number of threads, -d: allow directory, -r: recursive

Advanced Operations

fromdoFolderimportFile, Directory, comparefromdoFolder.hashingimportFileHashCalculator, multipleFileHash# File comparisonfile1=File("version1.txt")
file2=File("version2.txt")
ifcompare.compare(file1, file2):
print("Files are identical")
else:
print("Files differ")
# Directory comparison with detailed difference analysisdir1=Directory("./project_v1")
dir2=Directory("./project_v2")
diff=compare.getDifference(dir1, dir2)
ifdiff:
# Print all differences in flat structurefordindiff.toFlat():
print(f"Difference: {d.path1} vs {d.path2} - {d.diffType}")
# Advanced hashing with caching and multiple algorithmscalculator=FileHashCalculator()
file=File("important_data.txt")
# Single algorithmresult=calculator.get(file, "sha256")
print(f"SHA256: {result.hash}")
# Cached hashing for better performanceprint(f"The second result: {calculator.get(file).hash}")
file.content="New content".encode("utf-8")
# The cache will invalidate when file content changesprint(f"The third result: {calculator.get(file).hash}")
# Multiple algorithms at once (only one disk read is needed)results=calculator.multipleGet(file, ["sha256", "md5", "blake2b"])
foralgo, resultinresults.items():
print(f"{algo.upper()}: {result.hash}")

Path Utilities

Since v2.0.0, doFolder.Path is an alias for Python's built-in pathlib.Path, instead of the custom specialStr.Path from older versions.

For detailed information, please see pathlib documentation.

💻 Command-Line Interface

doFolder provides powerful command-line tools for file system operations with both unified and direct command interfaces.

Installation & Usage

After installing doFolder, you get access to several command-line tools:

# Install doFolder
pip install doFolder
# Direct commands (shortcuts)
do-compare /path1 /path2 # File/directory comparison
do-hash file.txt # File hashing# Unified interface
do-folder compare /path1 /path2 # Same as do-compare
do-folder hash file.txt # Same as do-hash# Python module interface
python -m doFolder compare /path1 /path2
python -m doFolder hash file.txt

Compare Command

Compare files or directories with various options:

# Basic comparison
do-compare file1.txt file2.txt
do-compare /directory1 /directory2
# Different comparison modes
do-compare /dir1 /dir2 --compare-mode CONTENT # Compare file contents
do-compare /dir1 /dir2 --compare-mode SIZE # Compare file sizes
do-compare /dir1 /dir2 --compare-mode TIMETAG # Compare modification times# Synchronization
do-compare /source /backup --sync --sync-direction A2B # Sync A to B
do-compare /dir1 /dir2 --sync --sync-direction BOTH # Bidirectional sync# Overwrite handling
do-compare /dir1 /dir2 --sync --overwrite AUTO # Auto decide by timestamp
do-compare /dir1 /dir2 --sync --overwrite ASK # Ask for each conflict

Hash Command

Calculate file hashes with multiple algorithms and options:

# Basic hashing (uses SHA256 by default)
do-hash file.txt
# Multiple algorithms
do-hash -a sha256,md5,sha1 file.txt
do-hash -a blake2b important_document.txt -a md5,sha1 another_file.txt
# Directory hashing
do-hash -d /directory # Hash all file in directory(no recursion)
do-hash -r -d /project # Recursive directory hashing# Performance options
do-hash -n 8 -d -a sha256,md5,blake2b ./src
# Disable progress display for cleaner output
do-hash --no-progress -r -d /path/to/files
# Path formatting
do-hash -p /absolute/path/file.txt # Use absolute paths
do-hash -f file.txt # Always show full path

Global Options

All commands support these global options:

# Version information
do-folder -v # Show version
do-folder -vv # Show detailed version info# Output control
do-folder --no-color compare /dir1 /dir2 # Disable colored output
do-folder -w 120 hash file.txt # Set console width
do-folder -m hash file.txt # Mute warnings
do-folder -t compare /dir1 /dir2 # Show full traceback on errors

Practical Examples

Backup Verification:

# Compare original and backup, sync differences
do-compare /important/data /backup/data --sync --sync-direction A2B --overwrite AUTO

Development Workflow:

# Compare two versions of a project
do-compare /project/v1 /project/v2 --compare-mode CONTENT
# Hash all source files for change detection
do-hash -a blake2b -r /src --full-path

�🔧 Advanced Features

Command-Line Interface

doFolder provides comprehensive command-line tools with two usage modes:

Unified Interface:

# Main command with subcommands
do-folder compare /path/to/dir1 /path/to/dir2 --sync
do-folder hash -a sha256,md5 file1.txt file2.txt
# Using Python module
python -m doFolder compare /source /backup --compare-mode CONTENT
python -m doFolder hash -a blake2b -r /directory

Direct Commands:

# Direct command shortcuts
do-compare /path/to/dir1 /path/to/dir2 --sync --overwrite AUTO
do-hash -a sha256,md5 file1.txt file2.txt --thread-num 8

Compare Command Features

  • Multiple comparison modes (SIZE, CONTENT, TIMETAG, TIMETAG_AND_SIZE, IGNORE)
  • Directory synchronization with bidirectional support
  • Flexible overwrite policies (A2B, B2A, ASK, AUTO, IGNORE)
  • Relative timestamp formatting
  • Interactive conflict resolution

Hash Command Features

  • Support for multiple hash algorithms (SHA family, MD5, BLAKE2, SHA3, etc.)
  • Multi-threaded processing for performance
  • Recursive directory hashing
  • Progress tracking with detailed status
  • Flexible output formatting

Advanced Hashing System

doFolder includes a sophisticated hashing system with multiple optimization levels:

fromdoFolder.hashingimport (
FileHashCalculator,
ThreadedFileHashCalculator,
ReCalcHashMode,
MemoryFileHashManager
)
fromconcurrent.futuresimportwait# Basic calculator with cachingcalculator=FileHashCalculator(
algorithm="sha256",
useCache=True,
reCalcHashMode=ReCalcHashMode.TIMETAG# Only recalc if file modified
)
# Multi-threaded calculator for better performancewithThreadedFileHashCalculator(threadNum=8) asthreaded_calc:
# Process multiple files concurrentlyfutures= [threaded_calc.threadedGet(file) forfileinfile_list]
wait(futures)
results= [future.result() forfutureinfutures]
# Custom cache managerfromdoFolder.hashingimportLfuMemoryFileHashManagercalculator=FileHashCalculator(
cacheManager=LfuMemoryFileHashManager(maxSize=1000)
)

Error Handling Modes

doFolder provides flexible error handling through UnExistsMode:

fromdoFolderimportFile, UnExistsMode# Different modes for handling non-existent filesfile1=File("missing.txt", unExistsMode=UnExistsMode.ERROR) # Raises exceptionfile2=File("missing.txt", unExistsMode=UnExistsMode.WARN) # Issues warningfile3=File("missing.txt", unExistsMode=UnExistsMode.IGNORE) # Silent handlingfile4=File("missing.txt", unExistsMode=UnExistsMode.CREATE) # Creates if missing

File System Item Types

fromdoFolderimportItemType, createItem# Factory function to create appropriate objectsitem1=createItem("./some_path", ItemType.FILE) # Creates File objectitem2=createItem("./some_path", ItemType.DIR) # Creates Directory objectitem3=createItem("./some_path") # Auto-detects type

🔄 Migration from v1.x.x

doFolder v2.x.x introduces several improvements while maintaining backward compatibility:

  • Enhanced Path Management: Now uses Python's built-in pathlib
  • Renamed Classes: FolderDirectory (backward compatibility maintained)
  • Flexible File Creation: File class can handle directory paths with redirection
  • Improved Type Safety: Full type hints throughout the codebase

Migration Example

# v1.x.x style (still works)fromdoFolderimportFolderfolder=Folder("./my_directory")
# v2.x.x recommended stylefromdoFolderimportDirectorydirectory=Directory("./my_directory")
# Both work identically!

📚 Documentation

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MulanPSL-2.0 License - see the LICENSE file for details.

About

It is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's `pathlib`, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

doFolder

PyPI versionGitHub RepositoryGitHub top languageLicenseDocumentation Status

doFolder is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's pathlib, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

✨ Key Features

  • 🎯 Object-oriented Design: Work with files and directories as Python objects
  • 🌐 Cross-platform Compatibility: Seamlessly works on Windows, macOS, and Linux
  • 🛤️ Advanced Path Handling: Built on Python's pathlib for robust path management
  • 📁 Complete File Operations: Create, move, copy, delete, and modify files and directories
  • 📝 Content Management: Read and write file content with encoding support
  • 🌳 Directory Tree Operations: Navigate and manipulate directory structures
  • 🔍 File Comparison: Compare files and directories with various comparison modes
  • 🔒 Hash Support: Generate and verify file hashes for integrity checking with multi-algorithm support
  • ⚡ High-Performance Hashing: Multi-threaded hash calculation with intelligent caching and progress tracking
  • 🖥️ Command-Line Tools: Comprehensive CLI interface with direct commands (do-compare, do-hash) and unified interface (do-folder)
  • ⚠️ Flexible Error Handling: Comprehensive error modes for different use cases
  • 🏷️ Type Safety: Full type hints for better IDE support and code reliability

📦 Installation

pip install doFolder

Requirements: Python 3.9+

Note: Python 3.8 is no longer supported since version 2.3.0

🚀 Quick Start

Command-Line Quick Start

After installation, you can immediately start using doFolder's command-line tools:

# Compare two directories
do-compare /path/to/source /path/to/backup
# Compare and sync directories
do-compare /path/to/source /path/to/backup --sync --sync-direction A2B
# Calculate file hashes
do-hash file1.txt file2.txt
# Calculate with specific algorithms
do-hash -a sha256,md5 README.md README.zh-cn.md
# Hash all files in a directory recursively
do-hash -r -d /path/to/project
# Use unified interface
do-folder compare /dir1 /dir2 --compare-mode CONTENT
do-folder hash -a blake2b *.py
# Or
python -m doFolder compare /dir1 /dir2 --compare-mode CONTENT
python -m doFolder hash -a blake2b *.py
# Note: do-folder is equal to python -m doFolder, use any of them you like

Python Quick Start

fromdoFolderimportFile, Directory, ItemType# Create directory and file objectsproject_dir=Directory("./my_project")
config_file=project_dir["config.json"]
# Create a new file in the directoryreadme=project_dir.create("README.md", ItemType.FILE)
readme_zh=project_dir.createFile("README.zh-cn.md")
# Write content to the filereadme.content="# My Project\n\nWelcome to my project!".encode("utf-8")
# Create a subdirectorysrc_dir=project_dir.create("src", ItemType.DIR)
# Copy and move filesbackup_config=config_file.copy("./backup/")
config_file.move("./settings/")
# List directory contentsforiteminproject_dir:
print(f"{item.name} ({'Directory'ifitem.isDirelse'File'})")

📖 Usage Examples

Working with Files

fromdoFolderimportFile# Create a file objectfile=File("data.txt")
# Work with binary contentprint(file.content) # Reads content as bytesfile.content="Binary data here".encode("utf-8") # Writes content as bytes# JSON operationsfile.saveAsJson({"name": "John", "age": 30})
data=file.loadAsJson()
# Quickly open filewithfile.open("w", encoding="utf-8") asf:
f.write("Hello, World!")
# File informationprint(f"Size: {file.state.st_size} bytes")
print(f"Modified: {file.state.st_mtime}")
# File hashingprint(f"Hash: {file.hash()}")
print(f"SHA256: {file.hash('sha256')}")
print(f"MD5: {file.hash('md5')}")
# Multi-threaded hashing for better performancefromdoFolder.hashingimportThreadedFileHashCalculatorwithThreadedFileHashCalculator(threadNum=4) ascalculator:
result=calculator.get(file)
print(f"Threaded hash: {result.hash}")

Working with Directories

fromdoFolderimportDirectory, ItemType# Create a directory objectd=Directory("./workspace")
# Create nested directory structured.create("src/utils", ItemType.DIR)
d.create("tests", ItemType.DIR)
d.createDir("docs")
d.createFile("README.md")
# Create filesmain_file=d.create("src/main.py", ItemType.FILE)
test_file=d.create("tests/test_main.py", ItemType.FILE)
# List all items (non-recursive)foritemind:
print(item.path)
# List all items recursivelyforitemind.recursiveTraversal(hideDirectory=False):
print(f"{'📁'ifitem.isDirelse'📄'}{item.path}")
# Find specific sub itemspy_files= ['__init__.py']

Command-Line Operations

doFolder provides powerful command-line tools for file system operations:

# Compare two directories with different modes
do-folder compare /path/to/dir1 /path/to/dir2 --compare-mode CONTENT
do-compare /path/to/dir1 /path/to/dir2 --sync --sync-direction A2B
# Calculate file hashes with multiple algorithms
do-folder hash -a sha256,md5 file1.txt file2.txt
do-hash -a blake2b -r /path/to/directory
# Use threading for better performance on large files
do-hash -n 8 -d -r -a sha256 /path/to/large_files/
# Options: -n: number of threads, -d: allow directory, -r: recursive

Advanced Operations

fromdoFolderimportFile, Directory, comparefromdoFolder.hashingimportFileHashCalculator, multipleFileHash# File comparisonfile1=File("version1.txt")
file2=File("version2.txt")
ifcompare.compare(file1, file2):
print("Files are identical")
else:
print("Files differ")
# Directory comparison with detailed difference analysisdir1=Directory("./project_v1")
dir2=Directory("./project_v2")
diff=compare.getDifference(dir1, dir2)
ifdiff:
# Print all differences in flat structurefordindiff.toFlat():
print(f"Difference: {d.path1} vs {d.path2} - {d.diffType}")
# Advanced hashing with caching and multiple algorithmscalculator=FileHashCalculator()
file=File("important_data.txt")
# Single algorithmresult=calculator.get(file, "sha256")
print(f"SHA256: {result.hash}")
# Cached hashing for better performanceprint(f"The second result: {calculator.get(file).hash}")
file.content="New content".encode("utf-8")
# The cache will invalidate when file content changesprint(f"The third result: {calculator.get(file).hash}")
# Multiple algorithms at once (only one disk read is needed)results=calculator.multipleGet(file, ["sha256", "md5", "blake2b"])
foralgo, resultinresults.items():
print(f"{algo.upper()}: {result.hash}")

Path Utilities

Since v2.0.0, doFolder.Path is an alias for Python's built-in pathlib.Path, instead of the custom specialStr.Path from older versions.

For detailed information, please see pathlib documentation.

💻 Command-Line Interface

doFolder provides powerful command-line tools for file system operations with both unified and direct command interfaces.

Installation & Usage

After installing doFolder, you get access to several command-line tools:

# Install doFolder
pip install doFolder
# Direct commands (shortcuts)
do-compare /path1 /path2 # File/directory comparison
do-hash file.txt # File hashing# Unified interface
do-folder compare /path1 /path2 # Same as do-compare
do-folder hash file.txt # Same as do-hash# Python module interface
python -m doFolder compare /path1 /path2
python -m doFolder hash file.txt

Compare Command

Compare files or directories with various options:

# Basic comparison
do-compare file1.txt file2.txt
do-compare /directory1 /directory2
# Different comparison modes
do-compare /dir1 /dir2 --compare-mode CONTENT # Compare file contents
do-compare /dir1 /dir2 --compare-mode SIZE # Compare file sizes
do-compare /dir1 /dir2 --compare-mode TIMETAG # Compare modification times# Synchronization
do-compare /source /backup --sync --sync-direction A2B # Sync A to B
do-compare /dir1 /dir2 --sync --sync-direction BOTH # Bidirectional sync# Overwrite handling
do-compare /dir1 /dir2 --sync --overwrite AUTO # Auto decide by timestamp
do-compare /dir1 /dir2 --sync --overwrite ASK # Ask for each conflict

Hash Command

Calculate file hashes with multiple algorithms and options:

# Basic hashing (uses SHA256 by default)
do-hash file.txt
# Multiple algorithms
do-hash -a sha256,md5,sha1 file.txt
do-hash -a blake2b important_document.txt -a md5,sha1 another_file.txt
# Directory hashing
do-hash -d /directory # Hash all file in directory(no recursion)
do-hash -r -d /project # Recursive directory hashing# Performance options
do-hash -n 8 -d -a sha256,md5,blake2b ./src
# Disable progress display for cleaner output
do-hash --no-progress -r -d /path/to/files
# Path formatting
do-hash -p /absolute/path/file.txt # Use absolute paths
do-hash -f file.txt # Always show full path

Global Options

All commands support these global options:

# Version information
do-folder -v # Show version
do-folder -vv # Show detailed version info# Output control
do-folder --no-color compare /dir1 /dir2 # Disable colored output
do-folder -w 120 hash file.txt # Set console width
do-folder -m hash file.txt # Mute warnings
do-folder -t compare /dir1 /dir2 # Show full traceback on errors

Practical Examples

Backup Verification:

# Compare original and backup, sync differences
do-compare /important/data /backup/data --sync --sync-direction A2B --overwrite AUTO

Development Workflow:

# Compare two versions of a project
do-compare /project/v1 /project/v2 --compare-mode CONTENT
# Hash all source files for change detection
do-hash -a blake2b -r /src --full-path

�🔧 Advanced Features

Command-Line Interface

doFolder provides comprehensive command-line tools with two usage modes:

Unified Interface:

# Main command with subcommands
do-folder compare /path/to/dir1 /path/to/dir2 --sync
do-folder hash -a sha256,md5 file1.txt file2.txt
# Using Python module
python -m doFolder compare /source /backup --compare-mode CONTENT
python -m doFolder hash -a blake2b -r /directory

Direct Commands:

# Direct command shortcuts
do-compare /path/to/dir1 /path/to/dir2 --sync --overwrite AUTO
do-hash -a sha256,md5 file1.txt file2.txt --thread-num 8

Compare Command Features

  • Multiple comparison modes (SIZE, CONTENT, TIMETAG, TIMETAG_AND_SIZE, IGNORE)
  • Directory synchronization with bidirectional support
  • Flexible overwrite policies (A2B, B2A, ASK, AUTO, IGNORE)
  • Relative timestamp formatting
  • Interactive conflict resolution

Hash Command Features

  • Support for multiple hash algorithms (SHA family, MD5, BLAKE2, SHA3, etc.)
  • Multi-threaded processing for performance
  • Recursive directory hashing
  • Progress tracking with detailed status
  • Flexible output formatting

Advanced Hashing System

doFolder includes a sophisticated hashing system with multiple optimization levels:

fromdoFolder.hashingimport (
FileHashCalculator,
ThreadedFileHashCalculator,
ReCalcHashMode,
MemoryFileHashManager
)
fromconcurrent.futuresimportwait# Basic calculator with cachingcalculator=FileHashCalculator(
algorithm="sha256",
useCache=True,
reCalcHashMode=ReCalcHashMode.TIMETAG# Only recalc if file modified
)
# Multi-threaded calculator for better performancewithThreadedFileHashCalculator(threadNum=8) asthreaded_calc:
# Process multiple files concurrentlyfutures= [threaded_calc.threadedGet(file) forfileinfile_list]
wait(futures)
results= [future.result() forfutureinfutures]
# Custom cache managerfromdoFolder.hashingimportLfuMemoryFileHashManagercalculator=FileHashCalculator(
cacheManager=LfuMemoryFileHashManager(maxSize=1000)
)

Error Handling Modes

doFolder provides flexible error handling through UnExistsMode:

fromdoFolderimportFile, UnExistsMode# Different modes for handling non-existent filesfile1=File("missing.txt", unExistsMode=UnExistsMode.ERROR) # Raises exceptionfile2=File("missing.txt", unExistsMode=UnExistsMode.WARN) # Issues warningfile3=File("missing.txt", unExistsMode=UnExistsMode.IGNORE) # Silent handlingfile4=File("missing.txt", unExistsMode=UnExistsMode.CREATE) # Creates if missing

File System Item Types

fromdoFolderimportItemType, createItem# Factory function to create appropriate objectsitem1=createItem("./some_path", ItemType.FILE) # Creates File objectitem2=createItem("./some_path", ItemType.DIR) # Creates Directory objectitem3=createItem("./some_path") # Auto-detects type

🔄 Migration from v1.x.x

doFolder v2.x.x introduces several improvements while maintaining backward compatibility:

  • Enhanced Path Management: Now uses Python's built-in pathlib
  • Renamed Classes: FolderDirectory (backward compatibility maintained)
  • Flexible File Creation: File class can handle directory paths with redirection
  • Improved Type Safety: Full type hints throughout the codebase

Migration Example

# v1.x.x style (still works)fromdoFolderimportFolderfolder=Folder("./my_directory")
# v2.x.x recommended stylefromdoFolderimportDirectorydirectory=Directory("./my_directory")
# Both work identically!

📚 Documentation

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MulanPSL-2.0 License - see the LICENSE file for details.

About

It is a powerful, intuitive, and cross-platform file system management library that provides a high-level, object-oriented interface for working with files and directories. Built on Python's `pathlib`, it simplifies common file operations while offering advanced features like hashing, content manipulation, and directory tree operations.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages