Add support for Windows file paths longer than 255 characters

master
Dan Howe 6 years ago
parent e9f99f54de
commit 1d2801aedd

@ -118,6 +118,13 @@ def download_document(url, document_path):
' Modification: {2}\n' ' Modification: {2}\n'
' Folder: {3}\n').format(*document_path.split(os.sep))) ' Folder: {3}\n').format(*document_path.split(os.sep)))
return return
# Check if destination path is too long (Windows filename limitation)
try:
open(document_path, 'a').close()
except FileNotFoundError:
document_path = '\\\\?\\' + os.path.abspath(document_path)
# Write file to disk # Write file to disk
with open(document_path, 'wb') as f: with open(document_path, 'wb') as f:
shutil.copyfileobj(r.raw, f) shutil.copyfileobj(r.raw, f)

Loading…
Cancel
Save