What is the maximum length of a file path?

INTRO

In many cases, Windows has a default limit of how many characters can make up a complete path to a file. That includes the length of the folder names. The limit is supposedly 260 characters for a path name. But, we've seen it actually stop at 255.To get around this limit, Windows allows you to make a change in the registry that will allow you to have a much longer path [in terms of number of characters in the path name] up to 32767 characters. A big increase!NOTE: These steps are to increase the path name size limit specifically for the Windows operating system itself. However Windows applications might choose to impose shorter path names. So, even though you'll increase the path name size length for Windows, you might might have a Windows app that might be programmed to not let you go past 255 characters.

Make A Registry Edit To Increase Path Length

Two ways to make the change. Either:Run the registry editor yourself [Method 1] orRun a prepared script to do it for you [Method 2], the easy method.

Method 1: Edit The Registry By-Hand If You Are Comfortable Making Registry Changes

  • Become an admin user on your system.
  • Run regedit
The key to change is located at:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabledSet the key’s DWORD value to “1”
  • Reboot to activate the change.

Method 2: Run A Script To Make The Change For You

  • Download the script to enable long pathnames on your windows system by clicking:
//support.cs.jhu.edu/Win-LongPathsEnabled/Win-LongPathsEnabled.zip
  • Unzip the downloaded file Win-LongPathsEnabled.zip
That will result in a file called LongPathsEnabled.reg
  • Double-click LongPathsEnabled.reg to run that file.
You may be prompted for admin account credentials. So, enter those to continue.
  • Reboot to activate the change.

  1. Last updated
  2. Save as PDF

Who is this article for?

Incydr Professional, Enterprise, Horizon, and Gov F2

Incydr Basic, Advanced, and Gov F1

Instructor, no.

Incydr Professional, Enterprise, Horizon, and Gov F2, no.

Incydr Basic, Advanced, and Gov F1, yes.

CrashPlan Cloud, no.

Retired product plans, no.

CrashPlan for Small Business, no.

Overview

If you are using the Windows operating system and your backup status isn't reaching 100%, one possible cause could be that you are backing up file paths and names that exceed a 255-260 character limit. This article provides a technical explanation for this issue and a recommended solution.

Affects

The Code42 app running on Windows [all versions, x86 and x64]

Before you begin

If you haven't done so already, you may want to start by reading our Windows solutions guide forUnable to Back Up X Files issues.

Under the hood

Microsoft has a core set of application programming interfaces [APIs] that programmers can use to interact with applications in the Windows operating system. These programming interfaces are often referred to as the Windows API. The Windows API imposes a maximum filename length such that a filename, including the file path to get to the file, can't exceed 255-260 characters.

However, because this is a limitation of the Windows API and not the file system used on the majority of Windows installations [NTFS], some programs can create filenames that violate this limit.

When the Code42 app attempts to read these files for backup, it fails because Windows doesn't know how to handle the file. When this occurs, the following error message displays in the Code42 app service.log:

WARN W196815609_BQTodoWkr 2.os.win.metadata.WindowsMetadataHandler] Problem getting named streams for file={filename}, e=java.io.FileNotFoundException: Could not open file...handleValue is invalid {filename}

Diagnosing

Symptoms of this issue include:

  • Your backup never reaches 100%
  • The Code42 app is running but certain files stay on the backup to-do list

It can be difficult to correct this issue. If you try to rename, move, or delete the file in Windows, you may receive the following messages:

Recommended solution

Since you are not able to move the files using Windows Explorer, you must use the subst command to shorten the file path for the file[s].

The simplest way to fix this is to:

  • Substitute the folder that has a long file path with a drive letter [thereby shortening the overall character count for the files contained in the folder]
  • Copy or move the files out of the folder into another folder that won't violate the limit
  • Delete the mapped folder

You can do this using either of the methods described below.

Method 1: Use the subst command to assign a drive letter to a specific folder

You can substitute a specific folder path with a drive letter using the Windows Command Prompt and the subst command. The command follows the format:

subst  

For example, if you wanted to replace the folder path C:\Example\File\Path with the drive letter Y, you would enter:

subst Y: C:\Example\File\Path

Now the Y: drive is "mapped" directly to the folder. Since you have substituted most of the long file path with Y:, it no longer violates the character limit. You can now move the files out of this folder to a folder with a shorter file path.

After you move the files, you can delete the virtual drive by running the subst command with the /d parameter. To delete the Y: drive created in the example above, enter:

subst Y: /d

Method 2: Use visual subst to assign a drive letter to a specific folder

If you aren't comfortable using the Windows Command Prompt, there is a free utility called Visual Subst that you can use to achieve the same results. Code42 does not create or test this software. If you choose to use it, we cannot provide support.

Information about the program and an example of its usage can be found at:

  • Visual Subst
  • How-To Geek: Walkthrough using Visual Subst or SUBST Command in Windows Command Prompt

External resources

  • Microsoft documentation on naming files, paths and namespaces
  • Blog discussing the logic surrounding the issue
  • Microsoft documentation for using the SUBST command
  • Wikipedia article about the SUBST command

Related topics

  • Unable to back up files [Windows]
  • File and folder hierarchy
  • Reference information for including or excluding files from backup
  • Why are files "missing" from my backup selection?
  • Renamed or "missing" external drive stops backup

What is the maximum length of the file?

Individual components of a filename [i.e. each subdirectory along the path, and the final filename] are limited to 255 characters, and the total path length is limited to approximately 32,000 characters. However, on Windows, you can't exceed MAX_PATH value [259 characters for files, 248 for folders].

What is the maximum file length in Windows?

The Windows API imposes a maximum filename length such that a filename, including the file path to get to the file, can't exceed 255-260 characters.

Why is there a 256 character limit?

The limit occurs due to an optimization technique where smaller strings are stored with the first byte holding the length of the string. Since a byte can only hold 256 different values, the maximum string length would be 255 since the first byte was reserved for storing the length.

What is the maximum file name length in Windows 10?

In Windows 10, you can enable long file name support, which allows file names up to 32,767 characters [although you lose a few characters for mandatory characters that are part of the name]. To enable this, perform the following: Start the registry editor [regedit.exe]

Chủ Đề