Sunday, February 23, 2020

OneDrive for business Path+File Name character limitation is misleading

I don’t understand why Microsoft would publish a document on limitation like this?
The Document “Restrictions and limitations when you sync files and folders Applies to: OneDrive for Business SharePoint Online” https://support.microsoft.com/en-us/help/3125202/restrictions-and-limitations-when-you-sync-files-and-folders
States,  “In SharePoint Online, file name paths can have up to 400 characters. The limit may be less than 400 characters in some scenarios, especially if you have a very long URL path for the library.
But it fails to state that the Microsoft Office Desktop Applications have different lower limits that are incompatible and present various unclear error messages when you try to open the files with the desktop application.
Also document should state the Microsoft Office Desktop application have different limitations.
Excel 2016 has a 218-character limit
Word, PowerPoint and Access 2016 are 259-character limit
https://support.microsoft.com/en-us/help/325573/you-receive-error-messages-when-you-try-to-open-an-office-document
Also Windows File explorer has a limited to 260-characters limit.
Now there is a GPO setting that enables long file name support but it doesn’t always work.
This document  “Restrictions and limitations when you sync files and folders Applies to: OneDrive for Business SharePoint Online” should include these other limitation, otherwise it's false advertising and very time consuming trying to get to the bottom of the unhelpful error messages.

Deleting directories/files with paths too long for Windows delete

In Windows API the maximum length for a path is defined by MAX_PATH  which is 260 characters. A local path is structured using drive letter, colon, backslash and folder names separated by backslashes, followed by a null terminator.
Windows has Unicode versions of file functions to provide an extended path length up to 32767 characters. The components used to create this path (separated by backslashes) can each have a value specified by the lpMaximumComponentLength  parameter. This value is commonly 255 characters. To specify an extended length path, the \\?\  prefix is used, like this:
You can not use the \\?\  prefix with a relative path, relative paths are always limited to a total of MAX_PATH  characters.
Note, in Windows 10 version 1607 onward, the MAX_PATH  limitations have been removed.
Many Windows applications expect the maximum path length to be less than 255 characters. When you try to copy or delete files you will see an error like “The file name(s) would be too long for the destination folder. You can shorten the file name and try again, or try a location that has a shorter path.” This problem often arises with website cache files.
There are several solutions to this problem.

7-Zip

Download and install 7-Zip . Use the 7-Zip the Manager to delete the folders. You must use SHIFT  + DEL  inside 7-Zip’s File Manager, otherwise Windows will try to delete the files.
7Zip File Manager
7Zip File Manager

Mapped Path

If the folder you want to delete is shared on another computer or server use a mapped drive half way down the path. You are shortening the overall character count for the files contained in the folder by substituting the folder (with a long file path) with a drive letter. You can copy or delete the files without violating the limit. When you’ve finished delete the mapped folder.

Rename Folders

Work your way into the path, renaming each successive parent folder to “a” and attempting to delete. You are shortening the path each time. You can normally delete after 4 or 5 iterations.
Windows Source Path Too Long

Use a Linux Live CD!

Boot from an Linux Live CD and delete.

Robocopy

Use robocopy  (pre-installed with Windows since Vista). For example, if you need to delete everything in C:\FilePathTooLongFolderNameBlahBlah create a new folder call C:\EmptyFolder (leave it empty), then open a command prompt and run:
Since there are no files or folders in the source directory (C:\EmptyFolder), it simply deletes the files and folders under the target directory (C:\FilePathTooLongFolderNameBlahBlah) recursively.
Delete the empty folder C:\EmptyFolder when finished.

Saturday, February 22, 2020

How To Fix Path too long Error

When extracting one of the installation zip files in Windows 10 PC, this error message: Error 0x80010135 “Path Too Long” appears. The error is caused when you use Windows Explorer or WinZip to extract files and find a path that exceeds the maximum number of characters.

0X80010135 Error

0X80010135 Error

Almost all computer users have problems copying, deleting or renaming files with one of these messages such as file name too long, not erasable, access denied or destination path too long. This happens because Windows/FAR is not able to copy, delete or rename path names longer than 256 characters. When working on one or more files with longer file names, you may be confused by error messages that seem incomprehensible. If you also encounter a similar problem and one of those error messages like: Path too long or access denied, then don’t panic, we help you do your job effortlessly.

To solve this problem, use a decompression program like 7-Zip that can handle long file paths. Otherwise, extract the files to the root directory or c:/temp.

Here are the steps to help you solve this Windows problem:

Try extracting it to the root folder.
How To Fix 0X80010135 Error

Windows has a limit of 260 characters in pathnames, so if the Zip file is placed in a folder (including the desktop), the files contained in the Zip file may exceed this limit and cannot be extracted.

Placing the ZIP file at the root of the system disk is the surest way to avoid this problem.

Know More About How To Fix ‘Filename Is Too Long’ Issue In Windows




If you’ve ever seen this issue, it was probably a simple fix for you. If you’ve seen this error more than twice, then you also know that it can be a complex issue to fix sometimes.
Let’s hope you only run into the easy fix variety, but we’ll prepare you for the less easy, guaranteed to work fixes too.

Why Is Filename Length Even An Issue In Windows?

There’s a long history of filename lengths being a problem for operating systems like Windows. There was a time when you couldn’t have filenames longer than 8 characters plus a 3-character file extension. The best you could do was something like myresume.doc. This was a restriction in place by the design of the file system.
Things got better as new versions of Windows came out. We went from an old, limited, file system to something called the New Technology File System (NTFS). NTFS took us to a point where a filename could be 255 characters long, and the file path length could potentially go up to 32,767 characters. So how can we possibly have filenames that are too long?
Windows has things known as system variables. These are variables that Windows relies upon to function, because Windows will always know what the variables mean and where they are, even when we’re moving bits and bytes all over the place. The system variable MAX_PATH is the one that restricts filenames and file paths to under 260 characters.
Being a variable, you’d think we could change it. No, we should not. It would be like pulling a thread out of a sweater. As soon as one system variable changes, other system variables and components dependent on them start to unravel. How do we fix it, then?

The Easy Fix

If you’re fortunate, you’ll get the error and know exactly what file’s name is causing the issue. Or at least where to find the file. Maybe you have a filename that looks something like:
C:\User\guymc\Documents\My Resumesresumewithanamesolongthatitcausesproblemsandbecomespartofsomeguysarticleonthewebhowdoyoulikemenow.docx
It’s obvious who the offender is in this case. Find the file in Windows Explorer, or File Explorer as it’s called in Windows 10, click once on it, hit F2 to rename it, and change that silly filename to something more reasonable. Problem solved.

The Less Easy Fixes

It isn’t always that easy to fix this problem. Sometimes you may not be able to change the names of files or directories for whatever reason.
The following solutions will do the trick for you. They aren’t hard to do.

Move, Delete, Or Copy Files Or Directories Using PowerShell

Sometimes you get an error when trying to move, delete, or copy directories where the character count for the file path is more than 260.
Note that the words directory and folder are interchangeable. We’ll use ‘directory’ going forward. The following PowerShell cmdlets can also be used on files.
Perhaps the file path looks something like:
C:\Users\guymc\Documents\This\Is\Exactly\The\Precise\Directory\Path\That\I\Need\To\Have\To\Keep\My\Files\Sorted\In\A\Manner\That\Makes\Sense\To\Me\So\Lets\Pretend\This\Is\An\Actual\Filepath\That\You\Might\Also\Have\On\Your\Windows\Computer\And\Not\Over\Think\It\Document.docx
That file path is 280 characters long. So we cannot copy the directory out of there to somewhere else with the normal copy-paste method.  We get the Destination Path Too Long error.
Let’s assume that for whatever reason, we can’t rename the directories in which the file is nested. What do we do?
Open PowerShell. If you haven’t used PowerShell yet, enjoy our article Using PowerShell for Home Users – A Beginner’s Guide. You can do the next steps without reading the article, though.
When PowerShell opens, you’ll be at the root of your user directory. Follow along assuming C:\Users\guymc is your user directory.
The directory named This is inside the Documents directory. To move into the Documents directory, we use the DOS command cd Documents
You’ll see the prompt change to C:\Users\guymc\Documents. That’s good. We’re working closer to the directories which will make things easier.

Copy Directory Using Copy-Item

We want to copy the directory This and its contents into ThatNewFolder. Let’s use the PowerShell cmdlet Copy-Item with the parameters -Destination and -Recurse.
-Destination tells PowerShell where we want the copy to be. -Recurse tells PowerShell to copy all the items inside to the destination. Copying leaves the originals where they are and makes all new ones in the destination.
Copy-Item This -Destination ThatNewFolder -Recurse

Move Directory Using Move-Item

Let’s say we want to move the directory This, and all the directories and files in it, to ThatNewFolder. Moving does not leave the original in place.
We can use the PowerShell cmdlet Move-Item with the parameters -Path and -Destination. -Path defines the item we want to move and -Destination tells PowerShell where we want it. 
The cmdlet will put This inside of ThatNewFolder. It will also move everything that is inside of the This directory. Move-Item can be used to move files or directories, and it works regardless of file path or filename length.
Move-Item -Path This -Destination ThatNewFolder
To make sure it worked, use the cd ThatNewFolder command to get into ThatNewFolder. Then use the dir command to list the directories in ThatNewFolder. You’ll see the This directory is in there.

Delete Directory Using Remove-Item

If we want to delete the This directory, and everything in it, we use the Remove-Item cmdlet.
The Remove-Item cmdlet has some built-in safety that makes it difficult to delete a directory with things inside of it. In our example, we know we want to delete everything, so we’ll use the parameters -Recurse to make it delete everything inside and -Force to make it do that without asking us if we’re sure for every item inside.
Be warned! Recovering anything deleted this way would be extremely difficult. You can try the methods in How to Recover Accidentally Deleted Files, but don’t expect much.
Remove-Item This -Recurse -Force
You can use the dir command again to make sure it is gone.

Make Windows 10 Accept Long File Paths

If you know you’re going to be using long file paths and long file names repeatedly, it’s easier to make Windows work for you. No sense using PowerShell to do the work every day.
There are two ways we can do this. One is for Windows 10 Home users and the other is for Windows 10 Pro or Enterprise users. These methods may work for Windows 8.1 or earlier, but we cannot guarantee that.

Make Windows 10 Home Accept Long File Paths

To make Windows 10 Home accept long file paths, we need to open the Registry Editor. If you haven’t worked in Registry Editor before, be cautious. Accidentally deleting or changing things in here can stop Windows from working completely.
Always make a backup of your registry before making any changes. Learn everything you need to know about that in our Ultimate Guide to Backing Up and Restoring the Windows Registry.
Once you have Registry Editor opened, and your backup made, navigate to the location HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem and find the key LongPathsEnabled.
Double-click on LongPathsEnabled. In the Value data: field, make sure the number 1 is in there. Click OK to commit the change.
Exit Registry Editor and you should be able to work with crazy long file paths now.

Make Windows 10 Pro Or Enterprise Accept Long File Paths

To allow Windows 10 Pro or Enterprise to use long file paths, we’re going to use the Group Policy Editor. It’s a tool that allows us to set policies on how Windows operates at the computer and the user levels.
We’ve got several articles on using group policy to do things like disabling or enabling Internet Explorer options, or adding a message to the logon screen.
Open the Group Policy Editor by going to the Start menu and typing in gpedit. The top result should be Edit group policy. Double-click on that.
Once the Group Policy Editor opens, navigate to Computer Configuration > Administrative Templates > System > Filesystem. There you’ll see the policy Enable Win32 long paths.
Double-click on it to edit the policy setting. Change it from Disabled to Enabled, then click the OK button to commit the change. 
The policy may not take effect right away. You can force the group policy to update, though.

That’s It

There are some other ways to work around long filenames and file paths, but what we’ve gone through here are the simplest, most effective methods.