Note: this question is about the newly supported win32 long paths (available since Windows 10 Version 1607, Build 14352) and not about extended UNC paths starting with \\?\
.
I enabled long path support via a group policy and rebooted my PC. I checked in the registry that both HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\FileSystem\LongPathsEnabled
and HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled
are set to 1
.
Then I opened a Python REPL and tried to create a directory that will exceed the 260-char limit, but failed:
>>> import os
>>> longdirname = 'a' * 300
>>> longdirname
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
>>> os.makedirs(longdirname)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\python27\lib\os.py", line 157, in makedirs
mkdir(name, mode)
WindowsError: [Error 3] The system cannot find the path specified: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
[Error 3] The system cannot find the path specified: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
I'm assuming that the long path support somehow didn't take effect here. Why is this and how can I properly enable it so that it works from Python scripts?
Update: I also tried directly calling a Win32 API function via pywin32 that claims in its documentation that it should support long paths, but failed again:
>>> import win32file
>>> longname = 'a' * 300
>>> win32file.CreateDirectoryW(longname, None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
error: (3, 'CreateDirectoryW', 'The system cannot find the path specified.')
(3, 'CreateDirectoryW', 'The system cannot find the path specified.')
Update 2: Also tried creating via individual components:
>>> for i in range(1, 300):
... win32file.CreateDirectoryW('a', None)
... os.chdir('a')
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
error: (206, 'CreateDirectoryW', 'The filename or extension is too long.')
(206, 'CreateDirectoryW', 'The filename or extension is too long.')
(os.makedirs
also won't work in this case)
Update 3: The following batch script will not fail:
@echo off
setlocal enableextensions enabledelayedexpansion
pushd
set /a count = 1
for /L %%i in (1,1,300) do (
mkdir a
cd a
echo %%i
)
endlocal
popd
So I'm assuming that this is somehow related to Python then.