Created
June 1, 2026 16:52
-
-
Save akobashikawa/c788550a22efe669a34f134d38bcc5f5 to your computer and use it in GitHub Desktop.
rename ebooks trimming suffixes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/env bash | |
| echo BEGIN | |
| # 1. Obtenemos el directorio donde reside ESTE script wrapper | |
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | |
| # 2. Apuntamos al script vecino usando esa ruta base absoluta | |
| SCRIPT_RENAME="${SCRIPT_DIR}/rename-zlibs.sh" | |
| find . -type f \( -name "*.pdf" -o -name "*.epub" \) -printf "%h\n" | sort -u | while read -r dir; do | |
| echo "$SCRIPT_RENAME" "$dir" | |
| "$SCRIPT_RENAME" "$dir" | |
| done | |
| echo END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/env bash | |
| # echo START | |
| # Si le pasamos un argumento (una ruta), nos movemos allá primero | |
| if [ ! -z "$1" ]; then | |
| cd "$1" || exit 1 | |
| fi | |
| SUFFIXES=( | |
| "-— (z-library.sk, 1lib.sk, z-lib.sk)" | |
| " (z-library.sk, 1lib.sk, z-lib.sk)" | |
| "-— (Z-Library)" | |
| "-(Z-Library)" | |
| " (Z-Library)" | |
| "(Z-Library)" | |
| " (z-lib.org)" | |
| ) | |
| for filename in *.pdf *.epub; do | |
| [ -e "$filename" ] || continue | |
| name="${filename%.*}" | |
| extension="${filename##*.}" | |
| echo "" | |
| echo "Filename: $filename" | |
| clean_name="$name" | |
| for sufix in "${SUFFIXES[@]}"; do | |
| clean_name="${clean_name%$sufix}" | |
| done | |
| echo "Clean name: $clean_name" | |
| if [ "$name" != "$clean_name" ]; then | |
| # 1. Propuesta base inicial | |
| proposed="$clean_name.$extension" | |
| # 2. Si la propuesta ya existe EN EL DISCO y NO es el mismo archivo que estamos procesando | |
| if [ -e "$proposed" ] && [ "$proposed" != "$filename" ]; then | |
| contador=1 | |
| # 3. Bucle iterativo: mientras el nombre con el sufijo numerado exista... | |
| while [ -e "${clean_name}-${contador}.${extension}" ]; do | |
| ((contador++)) # Incrementamos el número (1 -> 2 -> 3...) | |
| done | |
| # 4. Asignamos la propuesta definitiva que encontramos libre | |
| proposed="${clean_name}-${contador}.${extension}" | |
| fi | |
| echo "Original : $filename" | |
| echo "Propuesto: $proposed" | |
| echo "Comando : mv \"$filename\" \"$proposed\"" | |
| mv "$filename" "$proposed" | |
| fi | |
| done | |
| # echo END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment