Skip to content

Instantly share code, notes, and snippets.

@kompowiec
Created November 21, 2024 12:57
Show Gist options
  • Save kompowiec/3a7564ffcc691ee033fde310884cc0fd to your computer and use it in GitHub Desktop.
Save kompowiec/3a7564ffcc691ee033fde310884cc0fd to your computer and use it in GitHub Desktop.
CBR to CBZ converter
#!/bin/bash
# Find all CBR files recursively and process each
find . -type f -iname '*.cbr' | while read -r cbr_file; do
# Extract the directory and file name without extension
dir=$(dirname "$cbr_file")
base=$(basename "$cbr_file" .cbr)
# Create a temporary folder for extraction
temp_dir="${dir}/${base}_temp"
mkdir -p "$temp_dir"
# Extract CBR contents
echo "Extracting: $cbr_file"
unrar x -o+ "$cbr_file" "$temp_dir/" || { echo "Extraction failed for $cbr_file"; continue; }
# Compress the extracted files into a CBZ
cbz_file="${dir}/${base}.cbz"
echo "Creating CBZ: $cbz_file"
zip -r "$cbz_file" "$temp_dir"/* > /dev/null || { echo "Failed to create CBZ for $cbr_file"; rm -r "$temp_dir"; continue; }
# Clean up
rm -r "$temp_dir"
# Optional: Delete the original CBR file
# Uncomment the next line if you want to remove CBR files after conversion
# rm "$cbr_file"
echo "Converted: $cbr_file → $cbz_file"
done
@kompowiec
Copy link
Author

kompowiec commented Nov 21, 2024

To convert CBR to CBZ recursively in a directory structure, you can use a script. Is a script for Linux/Unix (Bash) or Windows with tools like Git Bash installed.

What It Does:

  1. Finds all .cbr files recursively using find.
  2. Extracts each .cbr into a temporary folder using unrar.
  3. Compresses the extracted content into a .cbz using zip.
  4. Optionally deletes the original .cbr file.

Notes:

  • Safety: It won't overwrite existing .cbz files unless explicitly set.
  • Dependencies: Ensure unrar and zip are installed.
  • Customization: Uncomment the line to delete .cbr files after conversion if desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment