Skip to content

mcbabo/rtree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

rtree - Modern Directory rtree Viewer

A fast, modern directory rtree viewer written in Rust with advanced filtering capabilities, parallel processing, and progress tracking.

Rust License

Features

  • πŸš€ Fast Parallel Processing - Multi-threaded directory scanning for large file systems
  • πŸ” Advanced Filtering - Filter by file extensions, size, modification date, and regex patterns
  • πŸ“Š Progress Tracking - Real-time progress bars for large directory scans
  • πŸ’Ύ Size Analysis - Human-readable file and directory sizes
  • 🎨 Colored Output - Beautiful rtree visualization with syntax highlighting
  • πŸ”— Symlink Support - Proper handling and display of symbolic links
  • ⚑ Smart Threading - Automatic parallelization based on directory size

Installation

From Source

git clone https://github.com/yourusername/rtree
cd rtree
cargo build --release

The binary will be available at target/release/rtree.

Using Cargo

cargo install --path .

Quick Start

# Basic usage
rtree /path/to/directory

# Show with progress and sizes
rtree /path/to/directory --progress --sizes

# Filter Rust files modified in last 7 days
rtree /path/to/project --ext rs --newer-than 7d

# Find configuration files
rtree /path/to/project --find config --progress

Usage

A modern directory rtree viewer with filtering capabilities

Usage: rtree [OPTIONS] <PATH>

Arguments:
  <PATH>  Directory path to display

Options:
  -d, --depth <DEPTH>           Maximum depth to traverse [default: 5]
  -s, --sizes                   Show file and directory sizes
      --ext <EXTENSIONS>        Filter by file extensions (comma-separated, e.g., "rs,toml,md")
      --min-size <SIZE>         Minimum file size (e.g., "1MB", "500KB")
      --max-size <SIZE>         Maximum file size (e.g., "10MB", "1GB")
      --newer-than <TIME>       Show files newer than specified time (e.g., "7d", "2h", "30m")
      --older-than <TIME>       Show files older than specified time (e.g., "30d", "1h")
      --include <PATTERN>       Include files matching regex pattern
      --exclude <PATTERN>       Exclude files matching regex pattern
  -f, --find <TERM>             Search for files/directories containing this term
      --dirs-only               Show only directories
      --files-only              Show only files
  -p, --progress                Show progress bar during scanning
      --no-parallel             Disable parallel processing (use single thread)
  -h, --help                    Print help
  -V, --version                 Print version

Size Format Examples

  • 1024, 1KB, 1K β†’ 1024 bytes
  • 1.5MB, 1.5M β†’ 1.5 megabytes
  • 2GB, 2G β†’ 2 gigabytes
  • 500 β†’ 500 bytes (no unit)

Time Format Examples

  • 7d, 7days β†’ 7 days ago
  • 2h, 2hours β†’ 2 hours ago
  • 30m, 30mins β†’ 30 minutes ago
  • 45s, 45secs β†’ 45 seconds ago -f, --find Search for files/directories containing term --ext Filter by file extensions (comma-separated) --min-size Minimum file size (e.g., "1MB", "500KB") --max-size Maximum file size (e.g., "10MB", "1GB") --newer-than Show files newer than specified time (e.g., "7d", "2h") --older-than Show files older than specified time (e.g., "30d", "1h") --include Include files matching regex pattern --exclude Exclude files matching regex pattern --dirs-only Show only directories --files-only Show only files -h, --help Print help -V, --version Print version

## Examples

### Basic rtree Display

```bash
# Simple rtree with default depth (5 levels)
rtree ~/Projects

# Custom depth
rtree ~/Projects --depth 3

# Show with file sizes
rtree ~/Projects --sizes --progress

Filtering by File Type

# Show only Rust and TOML files
rtree ~/rust-project --ext rs,toml

# Show only source code files
rtree ~/project --include "\.(rs|js|py|go)$"

# Exclude build directories and files
rtree ~/project --exclude "(target|node_modules|\.git|\.DS_Store)"

Size-based Filtering

# Find large files (>10MB)
rtree ~/Downloads --min-size 10MB --files-only

# Find small config files (<1KB)
rtree ~/configs --max-size 1KB --ext conf,ini,yaml

# Files between 1MB and 100MB
rtree ~/media --min-size 1MB --max-size 100MB

Date-based Filtering

# Files modified in the last week
rtree ~/Documents --newer-than 7d

# Old log files (older than 30 days)
rtree ~/logs --older-than 30d --ext log

# Recent source code changes
rtree ~/project --newer-than 1d --ext rs,js,py

Advanced Combinations

# Large Rust files modified recently
rtree ~/rust-project --ext rs --min-size 10KB --newer-than 3d --sizes

# Find test files in any language
rtree ~/project --include "test.*\.(rs|js|py)$" --progress

# Project overview excluding build artifacts
rtree ~/project --exclude "(target|build|dist|node_modules)" --depth 4 --sizes

Performance

rtree is designed for speed and can handle large directory structures efficiently:

  • Parallel Processing: Automatically uses multiple CPU cores for large directories
  • Smart Threading: Only parallelizes when beneficial (directories with >10 items)
  • Progress Tracking: Real-time feedback for long-running scans
  • Memory Efficient: Streams results without loading entire rtree into memory

Benchmarks

On a typical development machine scanning a Rust project with ~50k files:

  • Single-threaded: ~2.5 seconds
  • Multi-threaded: ~0.8 seconds
  • With filtering: ~0.3 seconds (when filters reduce result set)

Output Format

rtree produces clean, readable output with:

  • Directory Structure: Classic rtree-style indentation with Unicode characters
  • Color Coding:
    • πŸ”΅ Blue bold for directories
    • 🟑 Yellow highlighting for search matches
    • πŸ”· Cyan for symbolic links
    • Default for regular files
  • Size Information: Human-readable sizes (B, KB, MB, GB, TB)
  • Summary Statistics: Total item count and size when requested

Example output:

/home/user/rust-project (2.3 MB)
β”œβ”€β”€ Cargo.toml (1.2 KB)
β”œβ”€β”€ src/ (1.8 MB)
β”‚   β”œβ”€β”€ main.rs (15.4 KB)
β”‚   β”œβ”€β”€ lib.rs (2.1 KB)
β”‚   └── modules/
β”‚       β”œβ”€β”€ scanner.rs (25.8 KB)
β”‚       └── display.rs (18.3 KB)
└── target/ (512.7 KB)
    └── debug/
        └── rtree (498.2 KB)

Total: 1,247 items
Size: 2.3 MB

Architecture

rtree is built with a modular architecture for maintainability and extensibility:

src/
β”œβ”€β”€ main.rs       # Entry point and orchestration
β”œβ”€β”€ lib.rs        # Public API and module exports
β”œβ”€β”€ cli.rs        # Command-line argument parsing
β”œβ”€β”€ filter.rs     # File filtering logic
β”œβ”€β”€ item.rs       # Core data structures
β”œβ”€β”€ scanner.rs    # Directory traversal and parallel processing
β”œβ”€β”€ display.rs    # rtree formatting and output
β”œβ”€β”€ progress.rs   # Progress tracking and reporting
└── utils.rs      # Utility functions and helpers

Key Components

  • Scanner: High-performance parallel directory traversal using Rayon
  • Filter: Flexible filtering system supporting multiple criteria
  • Display: Clean rtree rendering with Unicode box-drawing characters
  • Progress: Real-time progress reporting using Indicatif
  • CLI: Professional command-line interface using Clap

Dependencies

  • clap - Command line argument parsing
  • rayon - Data parallelism for fast scanning
  • indicatif - Progress bars and spinners
  • colored - Terminal color output
  • regex - Pattern matching for filtering
  • anyhow - Error handling and context

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.

Development Setup

git clone https://github.com/yourusername/rtree
cd rtree
cargo build
cargo test

Running Tests

# Run all tests
cargo test

# Run with output
cargo test -- --nocapture

# Run specific module tests
cargo test utils::tests

License

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

Roadmap

  • Export Options: JSON, XML, CSV output formats
  • Interactive Mode: Navigate rtree with arrow keys
  • Git Integration: Show git status indicators
  • File Icons: Unicode icons based on file types
  • Watch Mode: Monitor directory changes in real-time
  • Configuration File: Save commonly used filter combinations
  • Duplicate Detection: Find and highlight duplicate files
  • Compression Analysis: Estimate potential space savings

Acknowledgments

  • Inspired by the classic Unix rtree command
  • Built with modern Rust for performance and safety
  • Uses Unicode box-drawing characters for clean output

Made with ❀️ in Rust

About

Modern directory rtree viewer written in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages