I am trying to create a script that walks a directory and renames files. I would like to be able to extract the filename and file extension separately, but if the file path contains either spaces or Swedish UTF8-characters such as ÅÄÖ, it breakes.
I've found the below shown snippet to extract the filename + extension here on SO, but as I am seeing that it works on paths with no UTF-chars or whitespace, I am thinking that I am not properly escaping my variables.
Perhaps I am doing something wrong. Any ideas on what I can do to make this work with paths with UTF8 chars and whitespace?
for file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do
FULLPATH="$file"
FILENAME=${FULLPATH##*/}
FILEEXTENSION=${FILENAME##*.}
BASEDIRECTORY=${FULLPATH%$FILENAME}
#Log the vars for debugging
echo "$FULLPATH" >> ~/Desktop/log.txt
echo "$FILENAME" >> ~/Desktop/log.txt
echo "$FILEEXTENSION" >> ~/Desktop/log.txt
echo "$BASEDIRECTORY" >> ~/Desktop/log.txt
done
$NAUTILUS_SCRIPT_SELECTED_FILE_PATHScan contain multiple paths, some of them quoted. Is there a way to avoid this variable?