I have read all the previous answers on StackExchange and on Google, but they don't seem to solve my problem.
Long paths in Python on Windows
Python long filename support broken in Windows
Long paths for python on windows - os.stat() fails for relative paths?
I am adding '\\?\' in front of my filename, but it does not help. Here is my MWE:
test_path = '\\\\?\\d:\\' + ''.join(['a']*260)
print(test_path)
print(len(test_path))
with open(test_path, 'w'):
pass
Just trying to save a long file on d:
fails with
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-13-1ec52b105f8b> in <module>
3 print(test_path)
4 print(len(test_path))
----> 5 with open(test_path, 'w'):
6 pass
OSError: [Errno 22] Invalid argument: '\\\\?\\d:\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
Shorter filenames go through just fine. I am using Python 3.7
.
What am I doing wrong?
Without '\\?\' the command fails with FileNotFoundError
, as expected.