A powerful command-line file organization tool written in Zig that automatically categorizes and organizes files in directories based on file extensions.
- Smart File Categorization: Automatically categorizes files into Documents, Images, Videos, Audio, Archives, Code, Data, Configuration, and Other
- Advanced Organization Options:
- Date-based organization: Organize files by creation or modification time (year, year-month, year-month-day)
- Size-based organization: Separate large files from regular files with customizable size threshold
- Duplicate file detection: Find and handle duplicate files with multiple strategies (skip, rename, replace, keep-both)
- Recursive directory processing: Process subdirectories with configurable depth control
- Custom Configuration: Support for JSON configuration files to define custom categories and file extensions
- Safe Operations: Dry-run mode to preview changes before execution
- Conflict Resolution: Automatic file renaming when conflicts occur
- Rollback Support: Ability to rollback file moves in case of errors
- Comprehensive Logging: Verbose output for detailed operation tracking
- Edge Case Handling: Robust handling of special characters, long filenames, empty files, and various edge cases
- Zig 0.13.0 or later
- Clone the repository:
git clone <repository-url>
cd zigstack- Build the project:
zig build-
The executable will be created in
zig-out/bin/zigstack -
(Optional) Add to your PATH or create an alias:
# Add to your shell profile (.bashrc, .zshrc, etc.)
alias zigstack="/path/to/zigstack/zig-out/bin/zigstack"zigstack [OPTIONS] <directory>
# or
zigstack <command> [OPTIONS] <directory>Starting with v0.3.0, ZigStack supports a rich command-based interface with six powerful commands, while maintaining 100% backward compatibility with v0.2.0 usage patterns.
| Command | Purpose | Status |
|---|---|---|
organize |
Organize files by extension, date, size, or duplicates | β Default |
analyze |
Disk usage analysis with detailed breakdowns | β Available |
dedupe |
Find and manage duplicate files | β Available |
archive |
Archive old files based on age | β Available |
watch |
Monitor directory and auto-organize files | β Available |
workspace |
Manage developer workspace projects | β Available |
organize - Smart file organization (default command)
zigstack organize --move /path/to/messy/directoryanalyze - Disk usage analysis
zigstack analyze --top 20 --content /path/to/analyzededupe - Duplicate file management
zigstack dedupe --auto keep-newest --hardlink /downloadsarchive - Age-based archiving
zigstack archive --older-than 6mo --dest ~/Archive /documentswatch - Automatic file organization
zigstack watch --rules watch-rules.json ~/Downloadsworkspace - Developer workspace cleanup
zigstack workspace cleanup --strategy moderate ~/CodeAll v0.2.0 usage patterns continue to work exactly as before:
# v0.2.0 style (still works - defaults to 'organize' command)
zigstack /path/to/directory
zigstack --move /path/to/directory
zigstack --by-date --move /path
zigstack --verbose --dry-run /path
# v0.3.0 style (new, explicit command)
zigstack organize /path/to/directory
zigstack organize --move /path/to/directory
zigstack organize --by-date --move /path
zigstack organize --verbose --dry-run /pathBoth styles produce identical results. The command-based interface provides a foundation for advanced functionality while ensuring existing scripts and workflows remain unaffected.
No migration required! Your existing scripts, aliases, and workflows will continue to work without any changes.
To use the new commands:
- All commands follow the pattern:
zigstack <command> [OPTIONS] <directory> - Use
zigstack <command> --helpfor command-specific help - See the docs/ directory for detailed command documentation
-h, --help- Display help message-v, --version- Display version information--config PATH- Specify custom configuration file (JSON format)-c, --create- Create directories (preview mode by default)-m, --move- Move files to directories (implies --create)-d, --dry-run- Show what would happen without doing it (default mode)-V, --verbose- Enable verbose logging
--by-date- Organize files by date (creation or modification time)--date-format FORMAT- Date organization format: year, year-month, year-month-day (default: year-month)--by-size- Separate large files from regular files--size-threshold MB- Size threshold for large files in MB (default: 100)--detect-dups- Enable duplicate file detection--dup-action ACTION- How to handle duplicates: skip, rename, replace, keep-both (default: skip)--recursive- Process subdirectories recursively--max-depth DEPTH- Maximum recursion depth (default: 10)
Preview File Organization (Default Mode)
# Analyze a directory and show how files would be organized
zigstack /path/to/directory
# Same as above with explicit command
zigstack organize --dry-run /path/to/directoryCreate Directories Only
# Create category directories without moving files
zigstack organize --create /path/to/directoryFull Organization (Create and Move)
# Create directories and move files into them
zigstack organize --move /path/to/directoryUsing Custom Configuration
# Use a custom configuration file for categorization
zigstack organize --config my-config.json --move /path/to/directoryVerbose Output
# Get detailed information about operations
zigstack organize --verbose --move /path/to/directory# Organize files by creation/modification year and month
zigstack --by-date --move /path/to/directory
# Organize files by year only
zigstack --by-date --date-format year --move /path/to/directory
# Organize files by full date (year/month/day)
zigstack --by-date --date-format year-month-day --move /path/to/directory# Separate large files (>100MB) from regular files
zigstack --by-size --move /path/to/directory
# Use custom size threshold (>50MB)
zigstack --by-size --size-threshold 50 --move /path/to/directory# Find and skip duplicate files (default behavior)
zigstack --detect-dups --move /path/to/directory
# Rename duplicate files (file.txt β file_1.txt, file_2.txt, etc.)
zigstack --detect-dups --dup-action rename --move /path/to/directory
# Replace duplicate files (keep the last one processed)
zigstack --detect-dups --dup-action replace --move /path/to/directory
# Keep both files with different names
zigstack --detect-dups --dup-action keep-both --move /path/to/directory# Process all subdirectories (up to 10 levels deep by default)
zigstack --recursive --move /path/to/directory
# Limit recursion depth to 3 levels
zigstack --recursive --max-depth 3 --move /path/to/directory# Organize by date with duplicate detection and recursive processing
zigstack --by-date --detect-dups --recursive --move /path/to/directory
# Size-based organization with custom threshold, recursive processing, and verbose output
zigstack --by-size --size-threshold 200 --recursive --max-depth 5 --verbose --move /path/to/directory
# Full feature demonstration: date organization, duplicate handling, size separation, recursive
zigstack --by-date --date-format year-month-day \
--detect-dups --dup-action rename \
--by-size --size-threshold 100 \
--recursive --max-depth 3 \
--verbose --move /path/to/directory# Basic disk usage analysis
zigstack analyze /path/to/directory
# Show top 20 largest files/directories
zigstack analyze --top 20 /path/to/directory
# Analyze with content metadata (image dimensions, video duration, etc.)
zigstack analyze --content /path/to/media
# Export analysis to JSON
zigstack analyze --json --output report.json /path/to/directory
# Analyze only files larger than 10MB
zigstack analyze --min-size 10 /path/to/directory
# Limit analysis depth
zigstack analyze --max-depth 3 /path/to/directory# Find duplicates (dry-run mode, shows what would happen)
zigstack dedupe /downloads
# Interactive duplicate management
zigstack dedupe --interactive /downloads
# Automatically keep newest files, delete duplicates
zigstack dedupe --auto keep-newest --delete /downloads
# Replace duplicates with hardlinks (saves space)
zigstack dedupe --auto keep-newest --hardlink /downloads
# Export duplicate report to CSV
zigstack dedupe --format csv --output duplicates.csv /downloads
# Find duplicates only for files larger than 1MB
zigstack dedupe --min-size 1048576 /media
# Summary only, no actions
zigstack dedupe --summary /documents# Archive files older than 6 months (dry-run)
zigstack archive --older-than 6mo --dest ~/Archive /documents
# Archive and move files older than 1 year
zigstack archive --older-than 1y --move --dest ~/Archive /documents
# Archive with original directory structure preserved
zigstack archive --older-than 6mo --preserve-structure --dest ~/Archive /documents
# Archive to compressed tar.gz file
zigstack archive --older-than 1y --compress tar.gz --dest ~/Archive /documents
# Archive only specific categories
zigstack archive --older-than 3mo --categories "videos,images" --dest ~/Archive /media
# Archive only large files
zigstack archive --older-than 6mo --min-size 100 --dest ~/Archive /documents# Watch ~/Downloads directory
zigstack watch ~/Downloads
# Watch with custom rules file
zigstack watch --rules watch-rules.json ~/Downloads
# Validate rules file without running
zigstack watch --validate-rules --rules watch-rules.json
# Watch with custom interval (check every 10 seconds)
zigstack watch --interval 10 ~/Downloads
# Watch with date-based organization
zigstack watch --by-date --date-format year-month ~/Documents
# Watch with verbose logging
zigstack watch --verbose --log ~/zigstack-watch.log ~/Downloads# Scan workspace for projects
zigstack workspace scan ~/Code
# Scan with custom inactive threshold (90 days)
zigstack workspace scan --inactive-days 90 ~/Projects
# Export workspace report as JSON
zigstack workspace scan --json --output workspace-report.json ~/Code
# Preview cleanup (dry-run)
zigstack workspace cleanup --dry-run ~/Code
# Cleanup with moderate strategy
zigstack workspace cleanup --strategy moderate ~/Code
# Cleanup only inactive projects
zigstack workspace cleanup --strategy aggressive --inactive-only ~/Code
# Cleanup only Node.js projects
zigstack workspace cleanup --project-type nodejs --artifacts-only ~/Code
# Cleanup dependencies only (keep build artifacts)
zigstack workspace cleanup --deps-only --inactive-only ~/Code============================================================
FILE ORGANIZATION - MOVING FILES
============================================================
Total files to organize: 12
Files grouped by category:
----------------------------------------
π Documents (3 files):
β’ report.pdf (.pdf)
β’ notes.txt (.txt)
β’ presentation.docx (.docx)
π Images (4 files):
β’ photo1.jpg (.jpg)
β’ logo.png (.png)
β’ diagram.svg (.svg)
β’ screenshot.webp (.webp)
π Code (5 files):
β’ main.zig (.zig)
β’ script.py (.py)
β’ config.json (.json)
β’ style.css (.css)
β’ index.html (.html)
Organization Summary:
----------------------------------------
Documents: 3 files (25.0%)
Images: 4 files (33.3%)
Code: 5 files (41.7%)
============================================================
Directory creation and file moving complete.
============================================================
============================================================
FILE ORGANIZATION - DATE-BASED ORGANIZATION
============================================================
Total files to organize: 15
Files organized by date:
----------------------------------------
π 2024/09 (8 files):
π Documents (3 files):
β’ report.pdf (.pdf)
β’ notes.txt (.txt)
β’ presentation.docx (.docx)
π Images (5 files):
β’ photo1.jpg (.jpg)
β’ logo.png (.png)
β’ diagram.svg (.svg)
β’ screenshot.webp (.webp)
β’ banner.gif (.gif)
π 2024/08 (4 files):
π Code (2 files):
β’ main.zig (.zig)
β’ script.py (.py)
π Data (2 files):
β’ database.json (.json)
β’ config.yaml (.yaml)
π 2024/07 (3 files):
π Audio (2 files):
β’ song.mp3 (.mp3)
β’ podcast.wav (.wav)
π Videos (1 files):
β’ demo.mp4 (.mp4)
Organization Summary:
----------------------------------------
2024/09: 8 files (53.3%)
2024/08: 4 files (26.7%)
2024/07: 3 files (20.0%)
============================================================
Date-based organization complete.
============================================================
============================================================
FILE ORGANIZATION - SIZE-BASED ORGANIZATION
============================================================
Total files to organize: 10
Files organized by size:
----------------------------------------
π Large Files (>100MB) (3 files):
β’ large_video.mp4 (450.2 MB)
β’ backup_archive.zip (235.8 MB)
β’ high_res_image.tiff (125.4 MB)
π Regular Files (7 files):
π Documents (2 files):
β’ report.pdf (2.1 MB)
β’ notes.txt (15.2 KB)
π Images (3 files):
β’ photo.jpg (850.5 KB)
β’ logo.png (45.3 KB)
β’ icon.svg (8.2 KB)
π Code (2 files):
β’ main.zig (12.4 KB)
β’ script.py (3.7 KB)
Organization Summary:
----------------------------------------
Large Files: 3 files (30.0%) - 811.4 MB total
Regular Files: 7 files (70.0%) - 45.8 MB total
============================================================
Size-based organization complete.
============================================================
zigstack comes with built-in categories for common file types:
- Documents:
.txt,.pdf,.doc,.docx,.md,.rtf,.odt,.tex - Images:
.jpg,.jpeg,.png,.gif,.bmp,.svg,.webp,.ico - Videos:
.mp4,.avi,.mkv,.mov,.wmv,.flv,.webm - Audio:
.mp3,.wav,.flac,.aac,.ogg,.m4a,.wma - Archives:
.zip,.tar,.gz,.rar,.7z,.bz2,.xz - Code:
.c,.cpp,.h,.py,.js,.ts,.java,.zig,.rs,.go,.sh - Data:
.json,.xml,.csv,.sql,.db,.sqlite - Configuration:
.ini,.cfg,.conf,.yaml,.yml,.toml - Other: Files that don't match any category
Create a JSON configuration file to customize categories and file extensions:
{
"version": "1.0",
"categories": {
"MyDocuments": {
"description": "My custom document types",
"extensions": [".mydoc", ".notes"],
"color": "#4A90E2",
"priority": 1
},
"ProjectFiles": {
"description": "Project-specific files",
"extensions": [".proj", ".workspace"],
"color": "#7ED321",
"priority": 2
}
},
"display": {
"show_categories": true,
"show_colors": false,
"group_by_category": true,
"sort_categories_by_priority": true,
"show_category_summaries": true,
"show_uncategorized": true,
"uncategorized_label": "Other"
},
"behavior": {
"case_sensitive_extensions": false,
"include_hidden_files": false,
"include_directories": false,
"max_depth": 1
}
}After basic organization, your directory will look like:
/your/directory/
βββ documents/
β βββ report.pdf
β βββ notes.txt
βββ images/
β βββ photo1.jpg
β βββ logo.png
βββ code/
β βββ main.zig
β βββ script.py
βββ misc/
βββ unknown_file
With --by-date --date-format year-month:
/your/directory/
βββ 2024/
β βββ 09/
β β βββ documents/
β β β βββ recent_report.pdf
β β β βββ meeting_notes.txt
β β βββ images/
β β βββ recent_photo.jpg
β βββ 08/
β β βββ code/
β β β βββ old_script.py
β β βββ data/
β β βββ backup.json
β βββ 07/
β βββ audio/
β βββ old_recording.mp3
βββ 2023/
βββ 12/
βββ documents/
βββ archive_document.pdf
With --by-size:
/your/directory/
βββ large_files/ # Files > size threshold
β βββ huge_video.mp4 # 500MB
β βββ large_archive.zip # 250MB
β βββ big_dataset.csv # 150MB
βββ regular_files/ # Files <= size threshold
βββ documents/
β βββ report.pdf # 2MB
β βββ notes.txt # 15KB
βββ images/
β βββ photo.jpg # 800KB
βββ code/
βββ script.py # 5KB
With --by-date --by-size:
/your/directory/
βββ 2024/
β βββ 09/
β β βββ large_files/
β β β βββ presentation_video.mp4 # 300MB
β β βββ regular_files/
β β βββ documents/
β β β βββ report.pdf # 2MB
β β βββ images/
β β βββ chart.png # 500KB
β βββ 08/
β βββ regular_files/
β βββ code/
β βββ script.py # 5KB
βββ 2023/
βββ 12/
βββ large_files/
βββ archive.zip # 1GB
By default, zigstack runs in preview mode, showing you exactly what it would do without making any changes.
When a file with the same name already exists in the destination directory, zigstack automatically renames the file by appending a number:
document.txtβdocument_1.txtphoto.jpgβphoto_1.jpg
If an error occurs during file moving, zigstack can automatically rollback all changes, restoring files to their original locations.
# Run all tests
zig build test
# Run unit tests only
zig build test-unit
# Run integration tests only
zig build test-integration
# Run with verbose output
zig build test --verbose# Run performance benchmarks
zig build benchmark
# Build with specific optimization level
zig build -Doptimize=ReleaseFast benchmarkSee docs/PERFORMANCE.md for detailed performance characteristics and benchmarking information.
# Build with debug information
zig build -Doptimize=Debug- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass:
zig build test - Submit a pull request
zigstack robustly handles various edge cases:
- Empty files: Organized based on extension, regardless of file size
- Files without extensions: Categorized as "Other"
- Special characters: Filenames with spaces, dashes, underscores, and numbers
- Hidden files: Files starting with
.(can be included with configuration) - Long filenames: Proper handling of filesystem limits
- Invalid characters: Safe handling of unusual characters in filenames
- Permission issues: Clear error messages and graceful handling
- Disk space: Checking for available space before operations
- Date-based organization:
- Files with invalid or missing timestamps (fallback to current time)
- Future dates (properly handled without issues)
- Files from different time zones
- Leap years and month boundaries
- Size-based organization:
- Zero-byte files (treated as regular files)
- Extremely large files (>1TB, proper memory management)
- Sparse files and symbolic links
- Duplicate detection:
- Files with identical content but different names
- Files with same name but different content
- Binary files, text files, and special file types
- Large files (streaming hash calculation to avoid memory issues)
- Recursive processing:
- Symbolic link cycles (prevented with path tracking)
- Deep directory structures (configurable depth limits)
- Permission issues in subdirectories (graceful handling)
- Mixed file systems and junction points
[License information would go here]
-
v0.3.0 (Current): Complete command system with six powerful commands
- Six Commands: organize, analyze, dedupe, archive, watch, and workspace
- analyze command: Disk usage analysis with visualization, content metadata, and JSON export
- dedupe command: Interactive duplicate management with hardlink support and CSV export
- archive command: Age-based file archiving with compression (tar.gz) and structure preservation
- watch command: File system monitoring with automatic organization and custom rules
- workspace command: Developer workspace management with project detection and cleanup strategies
- 100% backward compatibility: All v0.2.0 CLI patterns continue to work unchanged
- Modular architecture: Refactored codebase with separate command and core modules
- Enhanced testing: 50+ tests covering all commands, backward compatibility, and edge cases
- Export functionality: JSON and CSV export for analyze and dedupe commands
- Rule-based automation: Custom rules engine for watch command (see examples/WATCH_RULES.md)
- Comprehensive documentation: Complete docs/ directory with tutorials and reference guides
-
v0.2.0: Advanced organization features (Issue #8)
- Date-based organization: Organize files by creation/modification time with configurable date formats
- Size-based organization: Separate large files from regular files with customizable thresholds
- Duplicate file detection: SHA-256 based duplicate detection with multiple handling strategies
- Recursive directory processing: Process subdirectories with configurable depth control
- Enhanced command-line interface with 8 new options
- Comprehensive test suite for all new features
- Updated documentation with examples and usage patterns
-
v0.1.0: Initial release with basic file organization features
- File categorization by extension
- Directory creation and file moving
- Dry-run preview mode
- Custom configuration support
- Basic test suite
For issues, feature requests, or questions, please open an issue in the GitHub repository.