Add support for Windows file paths longer than 255 characters

master
Dan Howe 6 years ago
parent e9f99f54de
commit 1d2801aedd

@ -93,7 +93,7 @@ def get_document_list(mod_id, output_dir):
def download_document(url, document_path):
"""Download document from given url"""
# Create output directories as required
try:
os.makedirs(os.path.dirname(document_path), exist_ok=True)
@ -118,6 +118,13 @@ def download_document(url, document_path):
' Modification: {2}\n'
' Folder: {3}\n').format(*document_path.split(os.sep)))
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
with open(document_path, 'wb') as f:
shutil.copyfileobj(r.raw, f)

Loading…
Cancel
Save