Only call os.makedirs() when an open() call fails with a FileNotFoundError Might cause errors with some post processors etc, but for now I was unable to find any.