No release in over 3 years
A Ruby gem to organize files in directories based on configurable rules including extensions, keywords, and dates.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

 Project Readme

tidy-file-organizer

Ruby License

ๆ—ฅๆœฌ่ชž

A Ruby-based CLI tool to automatically organize files based on file names, folder names, and extensions.

Features

  • ๐Ÿ—‚๏ธ Extension-based Organization: Automatically classify by file types (images, documents, scripts, etc.)
  • ๐Ÿ” Keyword-based Organization: Flexible classification by keywords in filenames (higher priority)
  • ๐Ÿ“… Date-based Organization: Organize files by modification date (year, year-month, year-month-day)
  • ๐Ÿ” Duplicate Detection: Find duplicate files using SHA-256 hash comparison
  • ๐Ÿ—‘๏ธ Duplicate Removal: Automatically remove duplicate files while keeping one copy
  • ๐Ÿ”„ Recursive Mode: Recursively organize files in subdirectories
  • ๐Ÿงช Dry-run Mode: Simulate before actual execution with --dry-run option
  • โš ๏ธ Safe Execution: Duplicate file detection, organized folder exclusion
  • ๐Ÿงน Auto Cleanup: Automatically remove empty directories
  • ๐ŸŒ Internationalization: Full English/Japanese support based on LANG environment variable
  • โš™๏ธ Flexible Configuration: Save different organization rules per directory

Installation

Install as a Gem

gem build tidy-file-organizer.gemspec
gem install ./tidy-file-organizer-*.gem

Note: Installation messages will be displayed in English or Japanese based on your LANG environment variable.

Use in Development

bundle install
ruby -I lib ./exe/tidyify [command] [options]

Usage

1. Setup (Configure Organization Rules)

tidyify setup [directory_path]
# If directory_path is omitted, uses current directory

Configure organization rules interactively:

[1] Extension-based Organization Rules
------------------------------------------------------------
Default values:
  jpg,jpeg,png,gif,bmp,svg,webp:images
  pdf,doc,docx,xls,xlsx,ppt,pptx,txt,md:documents
  rb,py,js,ts,java,cpp,c,go,rs:scripts
  ...

[2] Keyword-based Organization Rules
------------------------------------------------------------
Default values:
  screenshot:screenshots
  invoice:billing
  ...

2. Dry-run (Simulation)

# Root directory only (simulation)
tidyify run [directory_path] --dry-run
# If directory_path is omitted, uses current directory

# Including subdirectories (simulation)
tidyify run [directory_path] --recursive --dry-run

Example output:

--- Starting organization (/path/to/dir) [Dry-run mode] [Recursive mode] ---
[Dry-run] photo1.jpg -> images/
[Dry-run] report.pdf -> documents/
[Dry-run] screenshot_2024.png -> screenshots/
โš ๏ธ  Conflict: image.jpg -> images/ (duplicate filename)

3. Execute Organization

# Execute organization (actual file moving)
tidyify run [directory_path]
# If directory_path is omitted, uses current directory

# Combined with recursive mode
tidyify run [directory_path] --recursive

Command Reference

Basic Organization

tidyify setup [directory]                    # Configure organization rules (defaults to current dir)
tidyify run [directory] --dry-run            # Dry-run (simulation, defaults to current dir)
tidyify run [directory]                      # Execute organization (defaults to current dir)
tidyify run [directory] --recursive          # Include subdirectories
tidyify run [directory] -r --dry-run         # Simulate in recursive mode

Date-based Organization

# Organize by year (e.g., 2023/, 2024/)
# If directory is omitted, uses current directory
tidyify organize-by-date [directory] --pattern=year

# Organize by year-month (e.g., 2023-01/, 2023-06/)
tidyify organize-by-date [directory] --pattern=year-month

# Simulate before actual execution
tidyify organize-by-date [directory] --pattern=year-month-day --dry-run

Duplicate File Management

# Find duplicate files
# If directory is omitted, uses current directory
tidyify find-duplicates [directory] --recursive

# Remove duplicate files (keeps first file, deletes others)
# Interactive mode: Asks for confirmation before deletion
tidyify remove-duplicates [directory] --recursive

# Skip confirmation with --no-confirm option
tidyify remove-duplicates [directory] --no-confirm

# Simulate removal
tidyify remove-duplicates [directory] --dry-run

Note: By default, remove-duplicates asks for confirmation with a [yes/no] prompt before deleting files. Use --no-confirm to skip this confirmation.

Configuration Files

Configurations are saved in:

~/.config/tidy-file-organizer/[MD5hash].yml

Each directory maintains its own independent configuration.

Example

Before (Unorganized)

Downloads/
โ”œโ”€โ”€ photo1.jpg
โ”œโ”€โ”€ photo2.png
โ”œโ”€โ”€ report.pdf
โ”œโ”€โ”€ invoice_2024.pdf
โ”œโ”€โ”€ script.rb
โ”œโ”€โ”€ memo.txt
โ””โ”€โ”€ screenshot_2024.png

After (Organized)

Downloads/
โ”œโ”€โ”€ images/
โ”‚   โ”œโ”€โ”€ photo1.jpg
โ”‚   โ””โ”€โ”€ photo2.png
โ”œโ”€โ”€ documents/
โ”‚   โ”œโ”€โ”€ report.pdf
โ”‚   โ””โ”€โ”€ memo.txt
โ”œโ”€โ”€ screenshots/
โ”‚   โ””โ”€โ”€ screenshot_2024.png
โ”œโ”€โ”€ billing/
โ”‚   โ””โ”€โ”€ invoice_2024.pdf
โ””โ”€โ”€ scripts/
    โ””โ”€โ”€ script.rb

Development

Run Tests

bundle exec rspec

Try with Test Data

# English filenames
ruby -I lib ./exe/tidyify setup spec/data/en
ruby -I lib ./exe/tidyify run spec/data/en --recursive

# Japanese filenames
ruby -I lib ./exe/tidyify setup spec/data/ja
ruby -I lib ./exe/tidyify run spec/data/ja --recursive

Technical Specifications

  • Language: Ruby 3.0+
  • Standard Libraries: yaml, fileutils, digest
  • Test Framework: RSpec 3.0+
  • Configuration Format: YAML

License

MIT License

Note: The file .rubocop.cookpad-styleguide.yml is not covered by the MIT License. It is part of Cookpad's Ruby Style Guide and is licensed under CC BY 3.0.

Acknowledgments

This project uses Cookpad's Ruby Style Guide for RuboCop configuration, which is licensed under CC BY 3.0.

Author

sachin21