Skip to content

reekdeb/cmdlooper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CmdLooper - Recursive Command-Line Tool Runner

A powerful, optimized command-line tool for running other command-line programs recursively on all files in a folder. Built with Rust and Clap.

Features

Recursive Processing - Process all files in a directory tree
🎯 File Filtering - Filter by file extension
📁 Flexible Output - Control output location and file extensions
🎨 Colorful Output - Clear, beautiful terminal output
Optimized - Fast and memory-efficient
🛡️ Safe - Proper error handling with no panics
🔄 Error Control - Stop on first error or continue processing
🔧 Argument Templating - Full control over child process arguments
📝 Smart File Handling - Skip, overwrite, or rename when files exist

Installation

cargo build --release

The binary will be available at target/release/cmdlooper.exe

Usage

Basic Usage

Process all files with a specific extension using a simple command:

cmdlooper --command my_tool --extension dat

This will execute my_tool <input_file> <output_file> for each .dat file found.

Advanced Examples

Example 1: File Conversion with Custom Output Directory

cmdlooper --command file_converter \
  --input ./source_files \
  --output ./converted \
  --extension dat \
  --output-extension out \
  --args --quality high {input} {output}

This processes all .dat files and converts them to .out format in a different directory.

Example 2: Batch Processing with Custom Arguments

cmdlooper --command processor \
  --input ./input_data \
  --output ./output_data \
  --extension src \
  --output-extension dst \
  --args -i {input} -o {output} --flag1 --flag2 value \
  --continue-on-error \
  --verbose

Example 3: Processing with Tool-Specific Options

cmdlooper --command custom_tool \
  --input ./data \
  --extension raw \
  --output-extension processed \
  --args -i {input} -o {output} --option value

Example 4: Without Output Extension Change

cmdlooper --command optimizer \
  --input ./data \
  --extension txt \
  --args --input {input} --output {output}

Example 5: Multiple File Extensions

Process multiple file types in a single run:

cmdlooper --command processor \
  --input ./data \
  --extension txt --extension dat --extension cfg \
  --output-extension processed \
  --args -i {input} -o {output}

# Or using short form:
cmdlooper -c processor -i ./data -e txt -e dat -e cfg -x processed

This will process all .txt, .dat, and .cfg files in the data directory.

Example 6: Handle Existing Files

# Skip existing files (default)
cmdlooper --command file_processor \
  --input ./data \
  --output-extension out \
  --if-exists skip

# Overwrite existing files
cmdlooper --command file_processor \
  --input ./data \
  --output-extension out \
  --if-exists overwrite

# Rename new files (appends _1, _2, etc.)
cmdlooper --command file_processor \
  --input ./data \
  --output-extension out \
  --if-exists rename

Command-Line Options

Option Short Description
--command -c Required. Command to execute for each file
--input -i Input folder to process (default: current directory)
--output -o Output folder (default: same location as input files)
--extension -e File extension(s) to filter (e.g., "dat", "txt"). Can specify multiple times
--output-extension -x Output file extension (e.g., "out", "processed")
--args -a Additional arguments to pass to the command
--continue-on-error Continue processing even if a file fails
--if-exists Action when output file exists: skip, overwrite, or rename (default: skip)
--input-placeholder Placeholder for input file in args (default: {input})
--output-placeholder Placeholder for output file in args (default: {output})
--verbose -v Enable verbose output
--help -h Print help information

Argument Templating

The tool supports flexible argument templating using placeholders:

  • {input} - Replaced with the input file path
  • {output} - Replaced with the output file path

Default Behavior

If you don't specify --args, the tool automatically passes the input and output files:

cmdlooper --command my_tool --extension txt
# Executes: my_tool input.txt output.txt

Custom Arguments

Specify custom arguments with placeholders:

cmdlooper --command my_tool \
  --extension txt \
  --args -i {input} -o {output} --quality high
# Executes: my_tool -i input.txt -o output.txt --quality high

Output

The tool provides colorful, informative output:

  • ⚙ Blue gear icon for processing files
  • ✓ Green checkmark for successful operations
  • ⊝ Yellow circle for skipped files (already exist)
  • ✗ Red X for failed operations
  • Summary statistics at the end

Error Handling

By default, the tool stops on the first error. Use --continue-on-error to process all files regardless of errors:

cmdlooper --command my_tool \
  --extension dat \
  --continue-on-error

Handling Existing Files

Control what happens when an output file already exists using the --if-exists option:

Skip (Default)

Skips files that already exist and continues to the next file. Skipped files are tracked separately in the summary.

cmdlooper --command processor --extension dat --if-exists skip

Overwrite

Overwrites existing output files without warning.

cmdlooper --command processor --extension dat --if-exists overwrite

Rename

Automatically renames the new file by appending a number (_1, _2, etc.) to avoid conflicts.

cmdlooper --command processor --extension dat --if-exists rename
# Creates: output.dat, output_1.dat, output_2.dat, etc.

Performance

  • Zero-copy processing where possible
  • Efficient directory traversal using walkdir crate
  • Minimal allocations for optimal performance
  • No panics - all errors are handled gracefully

Building from Source

# Debug build
cargo build

# Optimized release build
cargo build --release

# Run tests (if any)
cargo test

Dependencies

  • clap - Command-line argument parsing
  • walkdir - Recursive directory traversal
  • colored - Terminal color output
  • anyhow - Error handling

License

This project is provided as-is for your use.

Examples of Tools You Can Use

  • Image Processing: ImageMagick, various image converters
  • Video Encoding: FFmpeg, HandBrake CLI
  • Audio Processing: Sox, audio converters
  • Document Conversion: Pandoc, document processors
  • Data Processing: Custom data transformers, formatters
  • Compression: 7zip, compression utilities
  • Code Generators: Template processors, code generators
  • Custom Scripts: Any executable that takes input/output files

Troubleshooting

Command not found

Ensure the command you're running is in your PATH or provide the full path:

cmdlooper --command "C:\Program Files\MyTool\tool.exe" --extension dat

Permission denied

Make sure you have write permissions for the output directory.

No files processed

Check that:

  1. The input directory exists
  2. The file extension filter matches your files
  3. Use --verbose flag to see more details

About

Recursive Command-Line Tool Runner

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages