File Path Too Long Error Appears After Migration: OneDrive for Business Fix
🔍 WiseChecker

File Path Too Long Error Appears After Migration: OneDrive for Business Fix

After migrating files to OneDrive for Business, you may see a “File path too long” error. This happens because Windows and OneDrive have a 260-character path length limit. Files with deep folder structures or long file names exceed this limit during or after migration.

The root cause is that the migration tool copies the full path from the source location. If the source had nested folders, the combined path length in OneDrive can easily exceed 260 characters. OneDrive then fails to sync the file and shows the error.

This article explains how to identify files with paths that are too long, shorten them using built-in Windows tools, and prevent the error from recurring. You will learn two methods to fix the issue without third-party software.

Key Takeaways: Fixing File Path Too Long Errors After Migration

  • PowerShell Get-ChildItem with -Recurse and -Name: Lists all files whose full path exceeds 260 characters in a given folder.
  • File Explorer renaming or moving: Shorten folder names or move files to a shallower folder level to reduce path length.
  • OneDrive Known Folder Move: Prevents the error by mapping Documents, Desktop, and Pictures directly to OneDrive at a short base path.

ADVERTISEMENT

Why the File Path Too Long Error Occurs After Migration

Windows and the NTFS file system historically limit a full file path to 260 characters. This limit includes the drive letter, colon, backslashes, folder names, and the file name plus extension. OneDrive for Business enforces this same limit when syncing files.

During a migration, files are copied from a source location such as a local drive, a network share, or another cloud service. If the source had folders nested more than five or six levels deep, or if folder names are long, the resulting path in OneDrive can exceed 260 characters. For example, a file at C:\Users\JohnDoe\Documents\Projects\2025\Q1\ClientName\Proposal\FinalDraft\v3\report.docx already uses 98 characters before being placed in OneDrive. When moved to C:\Users\JohnDoe\OneDrive - Contoso\Documents\Projects\2025\Q1\ClientName\Proposal\FinalDraft\v3\report.docx, the path grows to over 140 characters. If the source path was already near 200 characters, the OneDrive path will exceed 260.

Microsoft has removed the 260-character limit in Windows 10 version 1607 and later for applications that opt in. However, OneDrive does not support long paths natively. The error appears as a notification in the OneDrive activity center: “File path too long” or “The file name you specified is not valid or too long.” The file remains in the OneDrive folder locally but does not sync to the cloud.

Steps to Identify and Fix Files with Paths Exceeding 260 Characters

You will use PowerShell to scan for files with paths longer than 260 characters. Then you will shorten the paths using File Explorer or a script. These steps assume you have already migrated the files to the local OneDrive folder.

  1. Open PowerShell as Administrator
    Press the Windows key, type PowerShell, right-click Windows PowerShell in the search results, and select Run as administrator. Click Yes in the User Account Control prompt.
  2. Navigate to the OneDrive folder
    In PowerShell, type cd $env:OneDrive and press Enter. This changes the current directory to your OneDrive folder. If this variable is not set, type cd "C:\Users\YourUsername\OneDrive - Contoso" with your actual username and organization name.
  3. Run the PowerShell script to list long paths
    Copy and paste the following command into PowerShell and press Enter:
    Get-ChildItem -Recurse -Name | Where-Object { $_.Length -gt 260 } | Out-File -FilePath "$env:USERPROFILE\Desktop\LongPaths.txt"
    This command scans all files and folders recursively. It writes the full relative paths of items exceeding 260 characters to a text file on your desktop named LongPaths.txt. The scan may take several minutes depending on the number of files.
  4. Open the LongPaths.txt file
    Navigate to your desktop and open LongPaths.txt in Notepad or any text editor. Each line shows a relative path from your OneDrive root. Review the list to understand which folders contain the longest paths.
  5. Shorten folder names or restructure folders
    Open File Explorer and go to the OneDrive folder. For each folder listed in LongPaths.txt, do one of the following:
    – Rename deep subfolders to shorter names. For example, rename FinalDraft to FD and Proposal to Prop.
    – Move files from deep folders to a higher level. For example, move report.docx from Proposal\FinalDraft\v3 directly into Proposal.
    – Delete empty or redundant folders. Right-click a folder and select Delete if it contains no files.
  6. Re-run the PowerShell script to verify
    After making changes, run the Get-ChildItem command again. If the LongPaths.txt file is empty or contains no new entries, all paths are now under 260 characters.
  7. Restart OneDrive sync
    Right-click the OneDrive cloud icon in the system tray and select Pause syncing for 2 hours. Then right-click again and select Resume syncing. OneDrive will re-scan the folder and upload the previously blocked files.

ADVERTISEMENT

If OneDrive Still Shows the Error After Shortening Paths

Files are not in the expected OneDrive folder

If you shortened paths but the error persists, verify that the files are actually inside the OneDrive folder. Open File Explorer and check the path in the address bar. It should start with C:\Users\YourUsername\OneDrive - YourOrg\. If the files are outside this folder, move them into the OneDrive folder manually.

The migration tool created folder names with special characters

Some migration tools append timestamps or GUIDs to folder names. These can add 30 to 40 characters to a path. Rename these folders to remove the extra characters. For example, rename ProjectX_20250315_142305 to ProjectX.

OneDrive sync is stuck on a different file

A single file with a long path can block the entire sync queue. If the error shows a different file name after your fix, repeat the PowerShell scan and shortening process for that new file. Continue until the LongPaths.txt file is empty.

Files On-Demand vs Always Keep on This Device: Effect on Path Length Errors

Item Files On-Demand Always Keep on This Device
Description Files are shown as online-only placeholders until opened Files are downloaded and kept locally at all times
Path length limit 260 characters for the local placeholder path 260 characters for the local file path
Effect on error Error still occurs because the placeholder path is subject to the same limit Error still occurs because the full path is written to disk
Recommended setting during migration Turn off Files On-Demand to force full download and catch path errors early Use this setting after shortening paths to ensure all files sync

After you have shortened all paths, you can turn Files On-Demand back on. Right-click the OneDrive cloud icon, select Settings, go to the Sync and backup tab, and under Files On-Demand, check Save space and download files as you use them.

You can now scan your OneDrive folder for files with paths exceeding 260 characters using PowerShell and shorten them manually. To prevent this error in future migrations, use a folder structure no deeper than four levels and keep folder names under 20 characters. For ongoing protection, enable the Windows long path support policy in Group Policy under Computer Configuration > Administrative Templates > System > Filesystem > Enable Win32 long paths, though OneDrive will still enforce its own limit.

ADVERTISEMENT