diff --git a/sdks/python/apache_beam/io/fileio.py b/sdks/python/apache_beam/io/fileio.py index 076ec9452e47..a90ba3a50e7e 100644 --- a/sdks/python/apache_beam/io/fileio.py +++ b/sdks/python/apache_beam/io/fileio.py @@ -708,6 +708,14 @@ def process(self, element, w=beam.DoFn.WindowParam): self.path.get(), move_to) + try: + filesystems.FileSystems.mkdirs(self.path.get()) + except IOError as e: + cause = repr(e) + if 'FileExistsError' not in cause: + # Usually harmless. Especially if see FileExistsError so no need to log + _LOGGER.debug('Fail to create dir for final destination: %s', cause) + try: filesystems.FileSystems.rename( move_from,