Created
January 9, 2026 16:19
-
-
Save angelbladex/2f9c090cb871450065d3cba6ea15c899 to your computer and use it in GitHub Desktop.
Reemplaza caracteres inválidos en nombres de archivo (según Windows) por guiones bajos
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/bash | |
| # renombrarArchivos.sh | |
| # Reemplaza caracteres inválidos en nombres de archivo (según Windows) por guiones bajos | |
| sanitize() { | |
| local dir="$1" | |
| # Procesamos en orden inverso (-depth) para evitar problemas con directorios renombrados | |
| find "$dir" -depth -name "*[<>:\"\\|?*]*" | while IFS= read -r item; do | |
| dirpath=$(dirname "$item") | |
| basename_old=$(basename "$item") | |
| basename_new=$(echo "$basename_old" | sed 's/[<>:"\\|?*]/_/g') | |
| if [ "$basename_old" != "$basename_new" ]; then | |
| echo "Renaming: $item → $dirpath/$basename_new" | |
| mv "$item" "$dirpath/$basename_new" | |
| fi | |
| done | |
| } | |
| # Uso: ./renombrarArchivos.sh /ruta/a/tu/directorio | |
| if [ $# -eq 1 ] && [ -d "$1" ]; then | |
| sanitize "$1" | |
| else | |
| echo "Uso: $0 <directorio>" | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment