From 9159cb8fb3d719b3f4435d1dd6f25d5739a2b626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 19 Mar 2020 21:12:18 +0100 Subject: [PATCH] remove trailing dots and spaces from directory names (#647) --- gallery_dl/util.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 232047c2..47fad9ec 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -726,6 +726,7 @@ class PathFormat(): def set_directory(self, kwdict): """Build directory path and create it if necessary""" + windows = os.name == "nt" # Build path segments by applying 'kwdict' to directory format strings segments = [] @@ -733,6 +734,9 @@ class PathFormat(): try: for formatter in self.directory_formatters: segment = formatter(kwdict).strip() + if windows: + # remove trailing dots and spaces (#647) + segment = segment.rstrip(". ") if segment: append(self.clean_segment(segment)) except Exception as exc: @@ -747,7 +751,7 @@ class PathFormat(): directory += sep self.directory = directory - if os.name == "nt": + if windows: # Enable longer-than-260-character paths on Windows directory = "\\\\?\\" + os.path.abspath(directory)