diff --git a/gallery_dl/path.py b/gallery_dl/path.py index 4d76863d..c34b8cd1 100644 --- a/gallery_dl/path.py +++ b/gallery_dl/path.py @@ -317,11 +317,18 @@ class PathFormat(): if self.temppath != self.realpath: # Move temp file to its actual location - try: - os.replace(self.temppath, self.realpath) - except OSError: - shutil.copyfile(self.temppath, self.realpath) - os.unlink(self.temppath) + while True: + try: + os.replace(self.temppath, self.realpath) + except FileNotFoundError: + # delayed directory creation + os.makedirs(self.realdirectory, exist_ok=True) + continue + except OSError: + # move across different filesystems + shutil.copyfile(self.temppath, self.realpath) + os.unlink(self.temppath) + break mtime = self.kwdict.get("_mtime") if mtime: