From a3734e2e563fa471cc54dfdec33b338167660900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 31 Oct 2025 21:00:29 +0100 Subject: [PATCH] [path] improve 'exists()' performance call 'os.stat()' directly --- gallery_dl/path.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gallery_dl/path.py b/gallery_dl/path.py index 763fb555..e4466d8f 100644 --- a/gallery_dl/path.py +++ b/gallery_dl/path.py @@ -160,8 +160,12 @@ class PathFormat(): def exists(self): """Return True if the file exists on disk""" - if self.extension and os.path.exists(self.realpath): - return self.check_file() + if self.extension: + try: + os.stat(self.realpath) # raises OSError if file doesn't exist + return self.check_file() + except OSError: + pass return False def check_file(self):