Created
June 16, 2021 11:22
-
-
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))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.