Skip to content

Instantly share code, notes, and snippets.

@Canorus
Created June 16, 2021 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Canorus/014aa250f60cc17d0aacff7b2ca12c2f to your computer and use it in GitHub Desktop.
Save Canorus/014aa250f60cc17d0aacff7b2ca12c2f to your computer and use it in GitHub Desktop.
Convert filenames to NFC so that DSM can correctly handle filenames (and files be seen from other OSes using NFD normalization(macOS/Linux))
#!/bin/sh
encode() {
prefix=$1
ls -a | while read line
do
if [ "." == "$line" ] || [ ".." == "$line" ]; then
continue
fi
BEFORE="$line"
AFTER=`echo "$BEFORE" | uconv -f utf-8 -t utf-8 -x NFC`
if [ -d "$BEFORE" ]; then
echo "$prefix Dir [$BEFORE]"
cd -- "$BEFORE"
encode "$prefix-"
cd ..
fi
if [ "$BEFORE" != "$AFTER" ]; then
if [ -e "$AFTER" ]; then
echo "target file existed, ignore [$BEFORE]"
continue
fi
mv "$BEFORE" "$AFTER"
echo "[$BEFORE] -> [$AFTER]"
fi
done
}
encode ""
@Canorus
Copy link
Author

Canorus commented Jun 16, 2021

I've been having issue with files disappearing from SMB shared folders. I contacted Synology support team and they gave me above script. I just went over this Reddit thread the other day and thought I can share the script. Issue has been fixed since.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment