Skip to content

Instantly share code, notes, and snippets.

@ameisehaufen
Created March 18, 2021 00:41
Show Gist options
  • Save ameisehaufen/7099c0d7b415955b9ec95903580efe3f to your computer and use it in GitHub Desktop.
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.
#!/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