๐ Recipe ยท SharePoint & OneDrive
Scan Synology NAS for File Paths Exceeding SharePoint Migration Limits
Identify files with paths longer than 400 characters on a Synology NAS before migrating to SharePoint Online or OneDrive
Complexity
Intermediate
Impact
migration-prep + data-audit + sharepoint + onedrive + file-server
Context
Why This Matters
SharePoint Online and OneDrive enforce a 400-character limit on the total decoded URL path of any file, including the site address, library name, folder hierarchy, and filename. Files that exceed this limit will fail to migrate or sync, often silently, leaving gaps in the destination tenant.
When migrating data from a Synology NAS (or any on-prem file server) to SharePoint/OneDrive, the source paths may look short on the NAS โ for example /volume1/Marketing/Campaigns/... โ but once the destination site URL (e.g. https://contoso.sharepoint.com/sites/Marketing/Shared Documents/) is prepended, the effective path can easily blow past 400 characters.
This recipe gives you two reliable ways to pre-flight your data: run a native Bash command over SSH directly on the Synology (fastest, avoids Windows' legacy 260-character path ceiling), or run a PowerShell script from a Windows workstation with the share mapped. Run this before kicking off any migration tool (Mover, ShareGate, Migration Manager) so you can remediate the offending paths up front.
Expected Outcomes
After completing this recipe you will have:
- A CSV or text report listing every file whose absolute path exceeds the character threshold you specify.
- The exact character count for each offending path, so you know how many characters need to be trimmed.
- A remediation worklist that can be handed to data owners for renaming, re-foldering, or archival decisions.
- Confidence that your SharePoint/OneDrive migration batch will not hit silent path-length failures.
Risks & Considerations
Things to watch out for
- Use the NAS-native approach when possible. Running the scan from Windows against a deeply nested share can itself fail because Windows' legacy Win32 API caps paths at 260 characters โ the very files you are hunting may be invisible to
Get-ChildItem. Bash over SSH on the Synology has no such limit. - Account for the destination URL prefix. Your Synology path does not yet include
https://tenant.sharepoint.com/sites/<SiteName>/<Library>/. That prefix is typically 60โ100+ characters. Scan at a lower threshold (e.g. 300โ350 characters) to leave headroom. - URL encoding inflates length. Spaces become
%20, ampersands become%26, and so on. A path full of spaces and special characters can grow 10โ20% longer once encoded. Err on the side of caution. - Illegal characters are a separate problem. SharePoint blocks
",*,:,<,>,?,/,\,|, and leading/trailing whitespace or periods. Path length is only one dimension โ audit for these too. - Write output to a known share. Do not write the report file inside the folder you are scanning if the folder tree is huge, or you will pollute your own results on re-runs.
- SSH access is privileged. Only the
administratorsgroup on DSM can SSH in. Disable SSH again after you finish if it is not normally on.
Required Permissions
| Permission | Why It's Needed |
|---|---|
| Synology DSM administrator account | Required to enable SSH and read across all shared folders regardless of ACLs. |
| SSH service enabled on DSM | Needed to run shell commands directly on the NAS (Control Panel > Terminal & SNMP). |
| Read access to target shares (Windows method) | The account running PowerShell must be able to traverse every folder under the mapped drive or UNC path. |
| PowerShell 5.1 or PowerShell 7+ (Windows method) | Get-ChildItem in modern PowerShell handles long paths better than older shells, especially with the LiteralPath parameter. |
The fastest way to get this done: just ask Dex. Copy the prompt below and paste it into your Dex conversation.
For IT Admins
Paste into Dex Pro
Manual walkthrough โ enable SSH and run the scan on the Synology
This is a command-line task at its core, but the GUI steps below get you to a shell prompt on the NAS.
1. Enable SSH on DSM
- Sign in to DSM as an administrator.
- Open .
- Check Enable SSH service. Leave the port at 22 (or change it and note the new port).
- Click Apply.
2. Connect via SSH
- From a Windows, macOS, or Linux workstation, open a terminal (Windows Terminal, PuTTY, iTerm, etc.).
- Run:
ssh admin-user@<nas-ip-or-hostname> - Accept the host key and enter the administrator password.
3. Run the path-length scan
- At the shell prompt, run the following (replace the path and threshold as needed):
sudo find /volume1/YourShare -print0 | \ while IFS= read -r -d '' p; do \ len=${#p}; \ if [ "$len" -gt 350 ]; then \ printf '%d\t%s\n' "$len" "$p"; \ fi; \ done | sort -rn > /volume1/YourShare/_long_paths.tsv - Wait for the prompt to return. On a multi-terabyte share this can take several minutes.
- Open File Station in DSM, navigate to the share, and download
_long_paths.tsv. - Open the file in Excel (tab-delimited) โ column A is the path length, column B is the full path, sorted longest first.
4. Disable SSH (optional but recommended)
Return to and uncheck Enable SSH service if it is not normally on.
Not applicable for this recipe. Synology DSM does expose a Web API, but it does not provide a filesystem-traversal endpoint that returns full paths for every file on a volume. A path-length audit is fundamentally a recursive filesystem walk, which is best done with shell access on the NAS (see the Bash script section) or from a mounted client. Use the shell approach above instead.
Script approach โ two options
Pick whichever is easier given your environment. The Bash option is preferred; the PowerShell option is a fallback for Windows-centric shops.
Option A: Bash on the Synology (recommended)
Save the downloadable script below as scan-long-paths.sh, copy it to a share on the NAS (e.g. /volume1/homes/admin/), and run it over SSH:
chmod +x scan-long-paths.sh
sudo ./scan-long-paths.sh /volume1/YourShare 350 /volume1/YourShare/_long_paths.tsvArguments:
$1โ root path to scan (required)$2โ character threshold (default 400)$3โ output file (default./long_paths.tsv)
Output is a tab-separated file: length<TAB>full_path, sorted longest first.
Option B: PowerShell from a Windows workstation
If the Synology share is already mounted (e.g. Z:\) or reachable via UNC (\\nas01\YourShare), run this from an elevated PowerShell prompt:
$Path = '\\nas01\YourShare'
$Limit = 350
$Out = "$HOME\Desktop\LongPaths.csv"
Get-ChildItem -LiteralPath $Path -Recurse -File -Force -ErrorAction SilentlyContinue |
Where-Object { $_.FullName.Length -gt $Limit } |
Select-Object @{N='Length';E={$_.FullName.Length}}, FullName |
Sort-Object Length -Descending |
Export-Csv -LiteralPath $Out -NoTypeInformation -Encoding UTF8Caveat: Windows PowerShell 5.1 can fail on paths that are already over ~260 characters because of the legacy MAX_PATH limit. Use PowerShell 7+ (which is long-path-aware by default) or prefix paths with \\?\. When in doubt, fall back to the Bash script run on the NAS itself.
Interpreting the output
- Sort by length descending and start remediation with the worst offenders.
- Group by parent folder โ often a single deeply nested project folder is responsible for hundreds of long paths, and re-homing that one folder fixes all of them.
- Re-run the scan after remediation to confirm zero results above your target threshold before starting the migration.
Next steps