#!/usr/bin/env bash

# Set a log file for any failures that occur
ELOG=/tmp/removeUnicode_error.log

# Find any previous error logs and remove ready for this run
[[ -f $ELOG ]] && rm $ELOG

# Set the internal field separator to just newlines \n
IFS=$'\n'

FILES="$(find .)"

# Iterate over all the files and dirs in the current location downwards matching the unicode version of -
for L in $(echo "$FILES"|grep "–"); do
    mv "${L}" "${L//–/-}"   2>> $ELOG && echo "Success: $L" || echo "Failure: $L"
done

# Iterate over all the files and dirs in the current location downwards matching the unicode version of opening "
for L in $(echo "$FILES"|grep "“"); do
    mv "${L}" "${L//“/\"}"  2>> $ELOG && echo "Success: $L" || echo "Failure: $L"
done

# Iterate over all the files and dirs in the current location downwards matching the unicode version of closing "
for L in $(echo "$FILES"|grep "”"); do
    mv "${L}" "${L//”/\"}"  2>> $ELOG && echo "Success: $L" || echo "Failure: $L"
done

# Iterate over all the files and dirs in the current location downwards matching the unicode version of '
for L in $(echo "$FILES"|grep "’"); do
    mv "${L}" "${L//’/\'}"  2>> $ELOG && echo "Success: $L" || echo "Failure: $L"
done
