Skip to content

Instantly share code, notes, and snippets.

@spyesx
Last active October 5, 2025 14:41
Show Gist options
  • Select an option

  • Save spyesx/dc1249e89a2f49a00b7853ab9efc152a to your computer and use it in GitHub Desktop.

Select an option

Save spyesx/dc1249e89a2f49a00b7853ab9efc152a to your computer and use it in GitHub Desktop.
Synology drive download unsynced due to invalid file name or attribute

Synology drive download unsynced due to invalid file name or attribute

Usage:

chmod +x syno_check.sh
./syno_check.sh /path/to/your/synology/sync/folder
#!/bin/bash
# Configuration
MAX_PATH_LENGTH=247 # Set to the most restrictive OS limit (Windows)
INVALID_CHARS='[\*\:\?\/\\\"<>\t\|\r]' # Common Synology invalid characters and control characters
# Get the directory path argument
TARGET_DIR="$1"
# Check if a directory path was provided
if [ -z "$TARGET_DIR" ]; then
echo "Usage: $0 <directory_path>"
exit 1
fi
# Check if the directory exists
if [ ! -d "$TARGET_DIR" ]; then
echo "Error: Directory not found: $TARGET_DIR"
exit 1
fi
sudo chattr -R -i "$TARGET_DIR"
echo "--- Synology Drive File/Path Validator ---"
echo "Target Directory: $TARGET_DIR"
echo "Checking for path length > $MAX_PATH_LENGTH and invalid characters: * : ? / \\ \" < > | (and control chars)"
echo "------------------------------------------"
echo ""
# Find all files and directories recursively and process them
find "$TARGET_DIR" -print0 | while IFS= read -r -d $'\0' PATH_FULL; do
# Get the relative path for comparison/reporting
PATH_RELATIVE="${PATH_FULL#$TARGET_DIR/}"
# 1. Check for Invalid Characters in the Path/Name
# The script checks the full path, as an invalid character anywhere will cause an issue.
if echo "$PATH_RELATIVE" | grep -qE "$INVALID_CHARS"; then
echo "🚨 Invalid Character Found:"
echo " Path: $PATH_FULL"
echo " Reason: Contains unsupported character(s)."
echo "---"
continue
fi
# Check for leading tilde (~), which Synology often skips
FILENAME=$(basename "$PATH_FULL")
if [[ "$FILENAME" == "~"* ]]; then
echo "⚠️ Potential Exclusion Found:"
echo " Path: $PATH_FULL"
echo " Reason: File name starts with a tilde (~), often excluded as a temp/system file."
echo "---"
continue
fi
# Check for unsupported reserved names (e.g., .DS_STORE, Thumbs.db)
if [[ "$FILENAME" == ".DS_STORE" || "$FILENAME" == "Thumbs.db" ]]; then
echo "⚠️ Potential Exclusion Found:"
echo " Path: $PATH_FULL"
echo " Reason: File name is a known excluded system file."
echo "---"
continue
fi
# 2. Check for Excessive Path Length (using the conservative Windows limit)
PATH_LENGTH=${#PATH_FULL}
if (( PATH_LENGTH > MAX_PATH_LENGTH )); then
echo "📏 Excessive Path Length Found:"
echo " Path: $PATH_FULL"
echo " Length: $PATH_LENGTH characters (Max $MAX_PATH_LENGTH recommended)."
echo "---"
continue
fi
done
echo ""
echo "--- Scan Complete ---"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment