I am trying to create an archive using shutil.make_archive
and it runs successfully on Linux but not on Windows.
Here is the code:
# archive_dir_path looks like this : old_outputs
# execution_datetime looks like this : 2021-08-26 17:44:34.189488
# archived_output_path looks like this : old_outputs\outputs_2021-08-26 17:44:34.189488
archived_output_path = os.path.join(archive_dir_path, f'outputs_{execution_datetime}')
shutil.make_archive(archived_output_path, 'zip', output_dir_path)
And here is a stacktrace:
Traceback (most recent call last):
File "main_log_story.py", line 200, in <module>
tb.move_old_outputs(output_dir_path, filtered_logs_dir_path)
File "C:\Users\EnzoMolion\dev\DataTeam\log-story\toolbox\tools_for_file_handling.py", line 306, in move_old_outputs
shutil.make_archive(rf"{archived_output_path}", 'zip', output_dir_path)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\shutil.py", line 1059, in make_archive
filename = func(base_name, base_dir, **kwargs)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\shutil.py", line 940, in _make_zipfile
with zipfile.ZipFile(zip_filename, "w",
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\zipfile.py", line 1251, in __init__
self.fp = io.open(file, filemode)
OSError: [Errno 22] Invalid argument: 'C:\\Users\\EnzoMolion\\dev\\DataTeam\\log-story\\old_outputs\\outputs_2021-08-26 17:44:34.189488.zip'
Why isn't Windows version of make_archive happy with this path that looks like a valid windows path (doesn't it?)?
I turned out that the problem was that my created filename contained a semicolon (:
) which is not valid within a Windows filename