Created
March 18, 2021 00:41
-
-
Save ameisehaufen/7099c0d7b415955b9ec95903580efe3f to your computer and use it in GitHub Desktop.
Script to rename files using only ascii chars, except spaces, etc... based on ISO9660.
This file contains 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
#!/usr/bin/env bash | |
arquivos_selecionados=( "$@" ) | |
for filePath in "${arquivos_selecionados[@]}"; do | |
dirName=$(dirname "$filePath") | |
fileBaseName=$(basename "$filePath") | |
fileName="$(echo "$fileBaseName" | rev | cut -d '.' -f2- | rev)" | |
fileExt="$(echo "$fileBaseName" | rev | cut -d '.' -f1 | rev | tr '[:upper:]' '[:lower:]')" | |
on_Accent='öüóőúéáàűíÖÜÓŐÚÉÁÀŰÍçÇãÃõÕâÂêÊôÔªº¹²³' | |
offAccent='ouooueaauiOUOOUEAAUIcCaAoOaAeEoOao123' | |
newFileName="$(echo "$fileName" | sed "y/$on_Accent/$offAccent/" | tr '[:upper:]' '[:lower:]' | sed -e "s/^[ _-]*//g;s/[ _-]*$//g;s/--*/-/g;s/[ _]*-/-/g;s/-[_ ]*/-/g;s/ - /-/g" | sed -e "s/[^A-Za-z0-9_-]/_/g;s/__*/_/g" | cut -c -160)" | |
mv -n "$filePath" $dirName/$newFileName.$fileExt || xmessage "Erro em $newFileName" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment