
Hab mal ein test gehackt:
[Codebox=python file=Unbenannt.py]import os
import tempfile
with tempfile.TemporaryDirectory(prefix="path_test_") as d:
def make_sub_dirs(path):
new_path = os.path.join(path, "12345678")
try:
os.mkdir(new_path)
except FileNotFoundError as err:
print("*** %s" % err)
return path
os.chdir(new_path)
print(len(new_path), new_path)
return make_sub_dirs(new_path)
path = make_sub_dirs(d)
print(len(path), path)
filename=""
for no in range(20):
filename+=str(no)
filepath=os.path.join(path, filename)
try:
with open(filepath, "w") as f:
f.write("foo")
except FileNotFoundError as err:
print("+++ %s" % err)
break
print(len(filepath), filepath)[/Codebox]
Ausgabe ist damit:
Die zweite Fehlermeldung ist dabei ja ein wenig komisch60 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678
69 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678
78 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678
87 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678
96 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678
105 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678
114 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678
123 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
132 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
141 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
150 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
159 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
168 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
177 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
186 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
195 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
204 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
213 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
222 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
231 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
240 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
*** [WinError 206] Der Dateiname oder die Erweiterung ist zu lang: 'C:\\Users\\jens\\AppData\\Local\\Temp\\path_test_3o0m08we\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678'
240 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678
242 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\0
243 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\01
244 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\012
245 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\0123
246 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\01234
247 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\012345
248 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\0123456
249 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\01234567
250 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\012345678
251 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\0123456789
253 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\012345678910
255 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\01234567891011
257 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\0123456789101112
259 C:\Users\jens\AppData\Local\Temp\path_test_3o0m08we\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\12345678\012345678910111213
+++ [Errno 2] No such file or directory: 'C:\\Users\\jens\\AppData\\Local\\Temp\\path_test_3o0m08we\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\12345678\\01234567891011121314'

Die Limitierung ist allerdings nur durch die Windows API, denn NTFS kann wohl 32K Pfadlängen, aber Python nutzt anscheinend die API.
Hier ist MAX_PATH aufgeführt: https://msdn.microsoft.com/en-us/librar ... px#maxpath
Mir ist das ganze nur aufgefallen, weil ich in PyHardLinkBackup den temporären Dateinamen aus dem original generiere und dabei zufällige Zeichen anhänge. Dann wird es zu lang, wenn man z.B. alle Windows User Profile-Verzeichnisse sichert:
-> https://github.com/jedie/PyHardLinkBack ... -176241894File "c:\users\jens\appdata\roaming\pyhardlinkbackup\lib\site-packages\PyHardLinkBackup\phlb\path_helper.py", line 23, in rename2temp
src.rename(temp_filepath)
File "C:\Program Files (x86)\Python35-32\lib\pathlib.py", line 1264, in rename
self._accessor.rename(self, target)
File "C:\Program Files (x86)\Python35-32\lib\pathlib.py", line 377, in wrapped
return strfunc(str(pathobjA), str(pathobjB), *args)
FileNotFoundError: [WinError 3] Das System kann den angegebenen Pfad nicht finden
Im Netz hab ich nicht viel gefunden, außer: http://www.xxcopy.com/xxtb_047.htm