From a3e1864a263792523a54922368c06dd51406b76d Mon Sep 17 00:00:00 2001 From: I-Al-Istannen Date: Fri, 24 Jul 2020 09:22:51 +0000 Subject: [PATCH] Allow long paths on windows If you start PFERD a few folders deep in your home directory, it is quite easy to reach the maximum path length limit on Windows (260 chars). This patch opts in to long paths ("\\?\" prefix) which lift that restriction at the cost of ugly path names. --- PFERD/organizer.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/PFERD/organizer.py b/PFERD/organizer.py index 2fe4316..1665f23 100644 --- a/PFERD/organizer.py +++ b/PFERD/organizer.py @@ -5,6 +5,7 @@ A organizer is bound to a single directory. import filecmp import logging +import os import shutil from pathlib import Path, PurePath from typing import List, Optional, Set @@ -44,8 +45,17 @@ class Organizer(Location): (e.g. update the timestamp), the path is also returned in this case. In all other cases (ignored, not overwritten, etc.) this method returns None. """ - src_absolute = src.resolve() - dst_absolute = self.resolve(dst) + # Windows limits the path length to 260 for *some* historical reason + # If you want longer paths, you will have to add the "\\?\" prefix in front of + # your path... + # See: + # https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation + if os.name == 'nt': + src_absolute = Path("\\\\?\\" + str(src.resolve())) + dst_absolute = Path("\\\\?\\" + str(self.resolve(dst))) + else: + src_absolute = src.resolve() + dst_absolute = self.resolve(dst) if not src_absolute.exists(): raise FileAcceptException("Source file does not exist")