Windows Server 2016 was finally released last week, meaning we can finally lift the idiotic 260 characters limitation for NTFS paths. In this post I’ll show you how to configure the «Enable Win32 long paths» setting for the NTFS file system, by a Group Policy Object (a GPO), and «LongPathsEnabled» in the Windows registry. This is still required for Windows Server 2022 and Windows Server 2019.
Maximum Path Length Limitation (MAX_PATH) in Windows Server
Microsoft writes about the Maximum Path Length Limitation on MSDN, and they write:
Maximum Path Length Limitation
In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is «D:\some 256-character path string<NUL>» where «<NUL>» represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)
Microsoft Developer Network: Naming Files, Paths, and Namespaces
In the past, this 260 characters limitation caused errors and discomfort. Especially in the web hosting branche where you sometimes have to be able to save long file names. This resulted in (too) long paths and thus errors.
For example, have a look at this WordPress #36776 Theme update error Trac ticket. Which was a duplicate of #33053 download_url() includes query string in temporary filenames.
Fortunately, this limitation can now be unset and removed. Per default the limitation still exists though, so we need to set up a Local Group Policy. Or a Group Policy (GPO) in my case, since my server is in an Active Directory domain network.
In this post you’ll learn how to set up a GPO to enable NTFS long paths in Windows Server 2016 and Windows Server 2022/2019 using the LongPathsEnabled registry value.
Enabling «Long Paths» doesn’t magically remove the 260 character limit, it enables longer paths in certain situations. Adam Fowler has a bit more information about this is. Or are you wondering how to increase the configured maxUrlLength value in Windows Server & IIS? This’ll fix an IIS error «The length of the URL for this request exceeds the configured maxUrlLength value«.
But first things first.
You need to be able to set up this GPO using administrative templates (.admx) for Windows Server 2016. Because, in my situation, my Active Directory server is Windows Server 2012 R2 and doesn’t provide GPO settings for 2016.
Download Administrative Templates (.admx) for Windows 10 and Windows Server 2016
If you are, as me, on Windows Server 2012 R2 (at the time of this writing), you need administrative templates (.admx files) for Windows Server 2016 to configure 2016 specific Group Policy Objects. The same goes for Windows Server 2022 and 2019.
These few steps help you setting them up in your environment.
Download and install administrative templates for Windows Server 2016 in your Windows Server 2012 R2 Active Directory
Folow these steps:
- Download Windows 10 and Windows Server 2016 specific administrative templates — or
.admxfiles. - Install the downloaded
.msifile Windows 10 and Windows Server 2016 ADMX.msi on a supported system: Windows 10 , Windows 7, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2. You also need user rights to run the Group Policy Management Editor (gpme.msc), or the Group Policy Object Editor (gpedit.msc). But that’s for later use. - The administrative templates are installed in
C:\Program Files (x86)\Microsoft Group Policy\Windows 10 and Windows Server 2016, or whatever directory you provided during the installation. Copy over the entire folder PolicyDefinitions to your Primary Domain Controller’sSYSVOL\domain\Policiesdirectory. - Verify you’ve copied the folder, and not just the files. The full path is:
SYSVOL\domain\Policies\PolicyDefinitions. This is explained in Microsoft’s Technet article Managing Group Policy ADMX Files Step-by-Step Guide.
That’s it, you now have Group Policy Objects available for Windows Server 2016. Let’s enable Win32 long paths support now.
Configure «Enable Win32 long paths» Group Policy
Learn how to set up WMI filters for Group Policy.
Now that you have your Windows Server 2016 Group Policy Objects available, it’s time to setup a GPO to enable NTFS long path support. Create the GPO in your preferred location, but be sure to target it on Windows Server 2016 only.
Please note that the GPO is called Enable Win32 long paths, not NTFS.
Enabling Win32 long paths will allow manifested win32 applications and Windows Store applications to access paths beyond the normal 260 character limit per node on file systems that support it. Enabling this setting will cause the long paths to be accessible within the process.
Start your Group Policy Management console and click through to the location where you want to add the GPO. Create a new GPO: Create a GPO in this domain, and Link it here..., and provide your GPO with a relevant name.
In the Settings tab, right click and choose Edit…. Now under Computer Configuration in the Group Policy Management Editor, click through to Policies > Administrative Templates > System > Filesystem. Configure and enable the Setting Enable Win32 long paths.
!’This screen configures the GPO «Enable Win32 long paths»‘
This is all you have to do to create the Group Policy for long Win32 paths. All that is left is to run gpupdate in an elevated cmd.exe command prompt.
Verify LongPathsEnabled registry value
If needed, you can use the following cmd.exe or PowerShell commands to verify the LongPathsEnabled registry value is set correctly:
C:\>reg query HKLM\System\CurrentControlSet\Control\FileSystem /v LongPathsEnabled
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\FileSystem
LongPathsEnabled REG_DWORD 0x1
PS C:\> (Get-ItemProperty "HKLM:System\CurrentControlSet\Control\FileSystem").LongPathsEnabled
1
Don’t forget about your Windows Server 2022 and Windows Server 2019 servers, they still require this LongPathsEnabled registy value.
Use PowerShell to configure «Enable Win32 long paths»
If your servers are not in an Active Directory network and you want to enable the «Win32 long paths» (or LongPathsEnabled registry value) you can use PowerShell for the job. Here is a small PowerShell script that adds the registry value if the script is run on an supported Windows Server version.
#
# Add LongPathsEnabled registry value using PowerShell
#
function Test-RegistryValue {
param (
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Path,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Value,
[switch]$ShowValue
)
try {
$Values = Get-ItemProperty -Path $Path | select-object -ExpandProperty $Value -ErrorAction Stop
if ($ShowValue) {
$Values
}
else {
$true
}
}
catch {
$false
}
}
# Windows Server 2016 build is 10.0.14393
[version]"10.0.14393"
[version] $winver = $(Get-CimInstance -Namespace root\cimv2 -Query "SELECT Version FROM Win32_OperatingSystem").Version
if($winver -ge [version]"10.0.14393") {
if ($(Test-RegistryValue "HKLM:System\CurrentControlSet\Control\FileSystem" LongPathsEnabled) -eq $false) {
New-ItemProperty -Path "HKLM:System\CurrentControlSet\Control\FileSystem" -Name LongPathsEnabled -PropertyType DWORD -Value 1 -Force
}
}
This script contains a function that tries to look up if the requested registry path / value already exists. If it returns false, New-ItemProperty is executed to add LongPathsEnabled with value 1 to the Windows. A reboot afterwards is required.
Enable Win32 long paths in Windows 11 and Windows 10 (Bonus!)
If your client computer running Windows 11 or Windows 10 is not in an Active Directory and/or does not have the above mentioned GPO active, you can enable it yourself in a local security policy (LSP). You do need administrator privileges to follow the next steps:
- As an administrator, start
gpedit.mscfor example in an elevated PowerShell terminal venster or through Start (Select the as administrator option). Press enter and Group Policy Editor opens. - Go to Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> Filesystem, then enable the Enable Win32 long paths option.
- Restart your computer.
Of course you can add the registry value manually as well. Want to silently import .reg file in your Windows registry?
Did you like Enable NTFS long paths GPO in Windows Server 2022, 2019 and Windows Server 2016?
Then please, take a second to support Sysadmins of the North and donate!
Paypal
Your generosity helps pay for the ongoing costs associated with running this website like coffee, hosting services, library mirrors, domain renewals, time for article research, and coffee, just to name a few.
Наверное у многих разработчиков решения (solution) рассортированы по различным папкам: рабочие, личные, экспериментальные и т.д. Проекты в них также могут иметь разветвленную структуру и длинные имена. При таком подходе, рано или поздно, можно получить ошибку при сборке проекта из-за того, что путь до файла превысил 260 символов. Однако c Visual Studio 2019 и MSBuild 16 это не проблема. Надо только сделать небольшую настройку.
Настраиваем Windows
Windows, начиная с Windows 10 и Windows Server 2016, поддерживает длинные пути до файлов. Но по-умолчанию эта настройка выключена. Чтобы ее задействовать необходимо изменить один параметр в Local Computer Policy:
- Запустите gpedit.msc из меню Start или нажав WinKey+R
- Перейдите в раздел Local Computer Policy > Computer Configuration > Administrative Templates > All Settings.
- Установите параметр Enable Win32 long paths в значение Enabled.
Настраиваем приложения
Можно заметить, что в описании настройки речь идет о поддержке длинных путей для приложений, у которых это заявлено в манифесте. Он должен содержать следующий параметр:
...
<windowsSettings>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
</windowsSettings>
...
Кстати, Visual Studio 2019 и MSBuild 16 уже имеют эту настройку. Поэтому теперь выборе где разместить проект можно не ограничиваться длинной пути в 260 символов. Только не стоит забывать, что при использовании сервера сборки (build server) на нем также необходимо выполнить данную настройку.
Long paths not working in windows 2019
- Press Win + R keys on your keyboard and type regedit then press Enter. …
- Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem.
- Edit LongPathsEnabled and set it to 1.
- Press Win + R keys on your keyboard and type gpedit.
- How do I extend Windows * Server 2016 file path support from 260 to to 1024 characters?
- What is the maximum length of path in Windows?
- What does it mean when the file path is too long?
- How do I enable long path support in Windows Server 2019?
- Does Windows Explorer support long paths?
- Can’t find enable NTFS long paths?
- Why is there a 256 character limit?
- Should I disable the path length limit?
- What is the maximum length of a file path?
- How do I determine file path length?
- What is the maximum number of characters allowed in a filename path?
- How do you fix Cannot open the file because the file path is more than 259 characters?
How do I extend Windows * Server 2016 file path support from 260 to to 1024 characters?
b) Navigate to the following directory: Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem > NTFS. c) Click Enable NTFS long paths option and enable it. These changes have been verified with Intel® Quartus® Prime Pro and Windows* Server 2016 build 1607 only.
What is the maximum length of path in Windows?
In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character.
What does it mean when the file path is too long?
If you are facing the error Destination Path Too Long when trying to copy or move a file to a folder, try the quick trick below. The reason you receive the error is that File Explorer failed to copy/delete/rename any path-name longer than 256 characters.
How do I enable long path support in Windows Server 2019?
Press Win + R keys on your keyboard and type gpedit. msc then press Enter. Group Policy Editor will be opened. Go to Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> Filesystem, then enable the Enable Win32 long paths option.
Does Windows Explorer support long paths?
However, the long paths are not supported under File Explorer with the latest Windows version. That is the reason why it is not working even tweaking the registry and Group Policy.
Can’t find enable NTFS long paths?
Go to Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> Filesystem. 3. There, double click and enable the option Enable NTFS long paths.
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.
Should I disable the path length limit?
Disabling the path length is better than shortening the path or the file name. Because if someone installed the Python in a directory more than a recommended length means it will cause the error. So using this option is much better.
What is the maximum length of a file path?
While Windows’ standard file system (NTFS) supports paths up to 65,535 characters, Windows imposes a maximum path length of 255 characters (without drive letter), the value of the constant MAX_PATH. This limitation is a remnant of MS DOS and has been kept for reasons of compatibility.
How do I determine file path length?
To run the Path Length Checker using the GUI, run the PathLengthCheckerGUI.exe. Once the app is open, provide the Root Directory you want to search and press the large Get Path Lengths button. The PathLengthChecker.exe is the command-line alternative to the GUI and is included in the ZIP file.
What is the maximum number of characters allowed in a filename path?
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).
How do you fix Cannot open the file because the file path is more than 259 characters?
The answer is to rename the file, the folders or move the file to a shorter path. There is a registry key that allows you to have long file paths now.
Hello World,
This post addresses a quite known issue related to file path length limitation in NTFS filesystem. Every system administrator or file server administrator has encountered this issue while trying to delete folders or files or simply restructuring file and folder structure. When trying to manipulate some files located in a deep folder structure, you might receive the infamous error message : Path Too Long
Click on Picture for Better Resolution
In this post, we will provide a quick way to overcome this NFTS File system limitation. In fact, we will present multiple options that you might be able to use within your environment and which will help your work when dealing with File Services….
So, Let’s go….
Overview
Our Scenario
We have been asked to provide some reporting on File server and disk space used by some specific divisions. No Third party tools available or authorized. Again, the best option would be to use PowerShell scripting capabilities. Using well-known cmdlet, we came up with this simple one-liner (this is used for demonstration purposes as a more complex script has been written)
(get-ChildItem -Force E:\DivisionA -Recurse | measure-Object Length -s ).sum/1MB
When running this command against the specified folders, we should obtain the total size of the folder and its contents (subfolders). Initially, the command was working fine. Eventually, we came up with a folder containing a lot of data but also really long file names !!! The infamous error came up also in PowerShell : The specified path or file or both are too long.
Click on Picture for Better Resolution
Obviously, this will make our work a little bit more complicated as we now have to identify which path is too long . There is also a high chance that other subfolders might contains really long file path.
To overcome this situation, there are a lot of tips and trick on Internet. You could try to shorten the path using UNC network path or you can use the old (but still useful) subst command or using third party tools. A lot of options exists. However, our goal was to provide a rather simple workaround to the situation and have it working (almost) 100 % of the time
Possible Workarounds
Using only Windows Settings and PowerShell technology, it would be possible to overcome this long path limitation but some of the solutions presented hereafter requires specific Operating System Version.
If you are running Windows 2016 or later
If you are running a modern operating system, you will have basically two options.
- Enabling support for long File Path through a GPO or
- via PowerShell cmdlet Get-ChildItem
Option 1 – Enable Long File Path Support
By default, Windows 2016 Server and later Operating Systems provide support file path up to 260 Characters. Windows 2016 Server and later can now support longer file path if the feature is enabled through Group Policy (or possibly through registry keys). This is quite a welcome feature but surprisingly not well known by a lot of system admins. To enable the feature through GPO, you create a group policy and you then expand Computer Settings > Administrative Templates > System > FileSystem and you will see the option Enable Win32 Long Paths
Click on Picture for Better Resolution
Next time you will work on a File Server that has long file path you should not get error message when trying to obtain file size information.
Note :
You can enable this feature via registry key by navigating to HKLM\SYSTEM\CurrentControlSet\Control\FileSystem and find the set value to 1 for the entry LongPathsEnabled. If you do not see the key, create it as a DWORD (32bit)
Click on Picture for Better Resolution
Option 2 – Using PowerShell
This option is more interesting for us. Without enabling long path support at the operating system, it’s possible to use the PowerShell cmdlet Get-ChildItem to overcome the long path limitation. You can use the command to access local files or Network Files through UNC Path. The following command and syntax should not complain about long path files…..
#If you are accessing files locally get-childItem -LiteralPath \\?\e:\TopFolders\ #If you are accessing files through network Share get-childItem -LiteralPath \\?\UNC\MyFileServerHostName\Share\
Using the LiteralPath option, you will be able to access long file paths through your scripts. This option is quite cool because it requires zero configuration changes at the operating system level. You just need to adapt your script accordingly.
If you are running Windows 2012 R2
Surprisingly (or not), a lot of organizations are still running on Windows 2012 R2. Actually, we just finished some Windows 2008 R2 migration to more recent Operating system. Usually, legacy applications can explain the use of older Operating system but also because people do not really like introducing changes in a perfectly working fine infrastructure. Anyway, coming back to our discussion, it’s should be quite clear that Windows 2012 R2 cannot take advantage of the new Enable Long Path feature as the GPO/setting is not supported.
We have to fall back to option 2 which is the PowerShell method. To be able to use this option, the Windows 2012 R2 machine needs to be running a supported version. To check which version of PowerShell you are running, open a PowerShell command Prompt and issue the following command
$PsVersionTable
Click on Picture for Better Resolution
If you see that version is set to 4.0, you will need to install the WMF 5.1 package (manually or through patch management solution) in order to have the -LiteralPath working as expected. The WMF 5.1 package will basically update the PowerShell version already installed on your system and expose the most recent PowerShell cmdlets and improvements that have been already integrated in Windows 2016 Operating system. The package can be found and downloaded on Microsoft Web site (at this location). In our scenario, we will install the update manually. Double-click on the downloaded executable. You will see something like this
Click on Picture for Better Resolution
Proceed with the installation. Wait for Completion. At the end, you will need to reboot the machine in order to apply the changes. You might need to plan this reboot based on your internal procedure
Click on Picture for Better Resolution
When the installation is completed, you can check again the PowerShell Version that available on your system.
Click on Picture for Better Resolution
When this is done, you will be able to issue the following PowerShell commands which should overcome the long path file limitation….
#If you are accessing files locally get-childItem -LiteralPath \\?\e:\TopFolders\ #If you are accessing files through network Share get-childItem -LiteralPath \\?\UNC\MyFileServerHostName\Share\
All Windows Versions
It’s also possible to bypass the long path limitations without updating Powershell Version or enabling the feature on Recent operating system. The following approach simply uses the Robocopy builtin tool that can deal with Long Path files. The following script demonstrate how to report folder size on a specific server even if long path exists.
#-------------------------------------------------------------------------------------------
# ScriptName : FolderSizeReport.ps1
# Description : Combining robocopy and Powershell to Report folders size while avoiding the
# long Path file error
# Version : 1.0
# Note : Original script can be found at learn-powershell.net
#-------------------------------------------------------------------------------------------
$data=Get-ChildItem 'c:\windows\System32'
$data | foreach {
$item = $_.FullName
$params = New-Object System.Collections.Arraylist
$params.AddRange(@("/L","/S","/NJH","/BYTES","/FP","/NC","/NDL","/TS","/XJ","/R:0","/W:0"))
$countPattern = "^\s{3}Files\s:\s+(?<Count>\d+).*"
$sizePattern = "^\s{3}Bytes\s:\s+(?<Size>\d+(?:\.?\d+)).*"
$return = robocopy $item NULL $params
If ($return[-5] -match $countPattern) {
$Count = $matches.Count
}
If ($Count -gt 0) {
If ($return[-4] -match $sizePattern) {
$Size = $matches.Size
}
} Else {
$Size = 0
}
$object = New-Object PSObject -Property @{
FullName = $item
Count = [int]$Count
Size = ([math]::Round($Size/1GB,2))
}
$object.pstypenames.insert(0,'IO.Folder.Foldersize')
Write-host "$($object.FullName);$($object.Count);$($object.Size) GB;$($_.LastAccessTime);$($_.LastWriteTime)"
$Size=$Null
}
Final Notes
This is it for this post ! Through this post, we have demonstrated how to quite easily overcome the Long path limitations found in Windows Operating Systems. Recent Operating systems version can handle in a better way this problem. Indeed, since Windows 2016, it’s possible to enable a feature that would allow the Operating System to overcome the 260 characters limitations in path files. Recent PowerShell version (5.1 or later) also include additional features that help overcome the long path limitation.
To conclude, it would be good to educate users in order to teach them how to save their files and using proper (and shorter) naming conventions
Hope you enjoyed this post
Till next time
See ya
- How do you fix source path is too long?
- Can a file path be too long?
- How long can a Windows file path be?
- How do I enable long path support in Windows 10 1607 and higher?
- How do I fix error 0x80010135 path too long?
- How do I enable long path support?
- How do I find a file path that is too long?
- What is the longest file path in Windows 10?
- How do I find my path length?
- How do I fix Windows path too long and file name is too long?
- Does path include filename?
- How do I increase the maximum path in Windows?
How do you fix source path is too long?
The source filename(s) are longer than is supported by the file system. Try moving to a location which has a shorter path name, or try renaming them to shorter name(s) before attempting this operation.
Can a file path be too long?
With the Anniversary Update of Windows 10, you can finally abandon the 260 character maximum path limit in Windows. … Windows 95 abandoned that to allow long file names, but still limited the maximum path length (which includes the full folder path and the file name) to 260 characters.
How long can a Windows file path be?
Long Paths on Windows Systems
While Windows’ standard file system (NTFS) supports paths up to 65,535 characters, Windows imposes a maximum path length of 255 characters (without drive letter), the value of the constant MAX_PATH. This limitation is a remnant of MS DOS and has been kept for reasons of compatibility.
How do I enable long path support in Windows 10 1607 and higher?
How to enable paths longer than 260 characters in Windows 10
- Hit the Windows key, type gpedit. msc and press Enter.
- Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > System > Filesystem > NTFS.
- Double click the Enable NTFS long paths option and enable it.
How do I fix error 0x80010135 path too long?
Error 0x80010135: Path too long is reported. Usually this error is caused when you use Windows Explorer or WinZip to extract files and it encounters a file path that exceeds the maximum character limit. To resolve this problem, you may use a decompression utility such as 7-Zip, that can handle long file paths.
How do I enable long path support?
Step-by-step guide. Navigate to Computer Configuration > Administrative Templates > System > Filesystem . On the right, find the «Enable win32 long paths» item and double-click it. Exit the Local Group Policy Editor and restart your computer (or sign out and back in) to allow the changes to finish.
How do I find a file path that is too long?
Open the controlling dialog
- Select Find | Long Filenames… or (Alt+I,N) from the main menu to open the dialog where you can specify exactly which files you want to find.
- If one or more folders are selected they will be automatically entered into the Paths filed of the dialog when it opens.
What is the longest file path in Windows 10?
Maximum Path Length Limitation
In editions of Windows before Windows 10 version 1607, the maximum length for a path is MAX_PATH, which is defined as 260 characters. In later versions of Windows, changing a registry key or using the Group Policy tool is required to remove the limit.
How do I find my path length?
Path Length Checker 1.11.
To run the Path Length Checker using the GUI, run the PathLengthCheckerGUI.exe. Once the app is open, provide the Root Directory you want to search and press the large Get Path Lengths button. The PathLengthChecker.exe is the command-line alternative to the GUI and is included in the ZIP file.
How do I fix Windows path too long and file name is too long?
How To Fix: «The File Name Is Too Long» (In Windows Explorer)
- STEP 1 — Locate The File That Is Giving You That Error.
- STEP 2 — Now That You Know The Location Of The File, Go To A Parent or Top Level Folder. …
- STEP 3 — Rename Parent Folder To Something Short Enough To Reduce The Character Count Below 260 characters.
Does path include filename?
Paths include the root, the filename, or both.
How do I increase the maximum path in Windows?
Go to Windows Start and type REGEDIT. Choose the Registry Editor. In the Registry Editor, navigate to the following location: at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem.
…
Choose the DWORD (32-bit) Value.
- Right-click the newly added key and choose Rename.
- Name the key LongPathsEnabled.
- Press Enter.
