View Single Post
Old 02-27-2023, 02:19 PM   #40
isarl
Addict
isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.
 
Posts: 293
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
Quote:
Originally Posted by isarl View Post
Code:
for file in $(find . -type f) ; do
    if [[ $(chardetect "$file" --minimal) == "Windows-1252" ]] ; then
        iconv -f cp1252 -t utf-8 "$f" -o "$f.utf8"
        mv "$f.utf8" "$f"
    fi
done
The more I look at this, the more I worry that it might break if your filenames have a space character in them or something. It might be better to use find's -execdir option instead. Maybe something like:

Code:
read -r -d '' bash_script <<'EOF'
if [[ $(chardetect "{}" --minimal) == "Windows-1252" ]] ; then
    iconv -f cp1252 -t utf-8 "{}" -o "{}.utf8"
    mv "{}.utf8" "{}"
fi
EOF
find . -type f -execdir bash -c "$bash_script" ';'

Last edited by isarl; 02-27-2023 at 02:25 PM. Reason: fix typo in find options
isarl is offline   Reply With Quote