From 1d2801aedd5cddd33e37209d9efe781a83ed58fc Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Fri, 17 Aug 2018 16:05:54 +1000 Subject: [PATCH] Add support for Windows file paths longer than 255 characters --- major_projects_grabber/major_projects_grabber.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/major_projects_grabber/major_projects_grabber.py b/major_projects_grabber/major_projects_grabber.py index 3d11040..99ddd06 100644 --- a/major_projects_grabber/major_projects_grabber.py +++ b/major_projects_grabber/major_projects_grabber.py @@ -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)