Folder redirection issue

Shahin Mortazave 486 Reputation points


We having an issue with our folder redirection to onedrive for osme of our users.

We have a policy that will automatically move the users data from the current location to the Onedrive. Policy works, but we have 3 users that thier files dont get copy to the onedrive. We did check the event logs and can see the event 502 folder redirection error that talk about long folder or extention names.

Any idea how can we get a list of all the folders and files that have a long name? Or it would be beter if we could solve the issue without asking the users to shorten thier folders paths.

We have Windows 10 ent as client.

A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,525 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
11,739 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Daisy Zhou 17,241 Reputation points Microsoft Vendor

    Hello @Shahin Mortazave

    Thank you for posting here.

    We can find the long folder or extention names with the following command:

    cmd /c "dir /b /s /a C:\Users\administrator\Documents" | ForEach-Object { if ($.length -gt 250) {$ | Out-File -append C:\longfilepath.txt}}

    For example:


    Get-ChildItem -Path C:\Users\administrator\Documents -Recurse | Where-Object {$_.FullName.Length -gt 250 }| Select-Object -ExpandProperty FullName | Out-File C:\longfilepath.txt

    For example:

    From the article below, we can define the length of characters as 260 or shorter if needed.

    MAX_PATH: This is the maximum length of a path according to the Windows API, defined as 260 characters.

    Long Paths in .NET, Part 1 of 3 [Kim Hamilton]

    Here is a similar case, we can refer to it.

    Redirect folder redirection: "Failed to apply ... The filename or extension is too long."

    Hope the information is helpful.

    Best Regards,
    Daisy Zhou

    0 comments No comments

  2. Shahin Mortazave 486 Reputation points

    Thanks for your reply,

    Both the cmdlet returen an error, so I did run this cmd /c dir /s /b |? {$_.length -gt 256} and show me the files with long names.

    I read also that we can enable the"Enable the Win32 long paths" policy in Windows 10. Does this policy only going to work with 32 bit APIs or enabling this will also solve the issue that we have as well?