Skip to content

Instantly share code, notes, and snippets.

@dannofx
Last active September 21, 2017 18:23
Show Gist options
  • Save dannofx/e1e11db6da640269ea89d3d1a2a293f3 to your computer and use it in GitHub Desktop.
Save dannofx/e1e11db6da640269ea89d3d1a2a293f3 to your computer and use it in GitHub Desktop.
Compress easch subdirectoryinside a directory to a cbz file
#!/bin/bash
if [ -z "$1" ]
then
echo "Specify the source directory."
echo "./joincbr.sh SOURCE_DIRECTORY"
exit 0
fi
SOURCE_DIRECTORY=$1
COLLECTION_NAME=$2
if ! [ -z "$COLLECTION_NAME" ]
then
mkdir "$COLLECTION_NAME"
fi
export count=0
find "$SOURCE_DIRECTORY" -name "*" -maxdepth 1 -mindepth 1 -type d -print0 | sort -z |while IFS= read -r -d '' file; do
#dest="$count/"
filename="${file##/*/}"
cbzfile="$COLLECTION_NAME $filename.cbz"
echo "Creating cbr file: $cbzfile"
ditto -c -k -X "$file" "$cbzfile"
if ! [ -z "$COLLECTION_NAME" ]
then
mv "$cbzfile" "$COLLECTION_NAME/"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment