Hi All,
I'm looking for solution to save 2 csv files to zip file using Python code (the command line with 7 zip or powershell solution won't work due to server limitation).
I have saved two .csv files in temporary location also want zip output in the same location with specific name and I'm giving this location in connection from Alteryx to Python Tool
Input1:C:\Users\Marta\AppData\Local\Temp\1\Engine_24212_35fd6c49052f464195d34f3bff699af8_\file1_m.csv
Input2:C:\Users\Marta\AppData\Local\Temp\1\Engine_24212_35fd6c49052f464195d34f3bff699af8_\file2_m.csv
Output: C:\Users\Marta\AppData\Local\Temp\1\Engine_24212_35fd6c49052f464195d34f3bff699af8_\package_file
Path: Output: C:\Users\Marta\AppData\Local\Temp\1\Engine_24212_35fd6c49052f464195d34f3bff699af8_\
The Python code I'm trying to use
import os, shutil
df = Alteryx.read("#1")
base_name=df['Output'][0]
root_dir=df['Path'][0]
base_dir=df['Input1']['0']
shutil.make_archive(base_name, zip, root_dir, base_dir')
[base_name] - full name of the .zip file to be created (including path but excluding file extension)
[root_dir] - folder where file you want to archive is located
[base_dir] - file name you want to archive
This code is working but only for one file, do you know how to modify it to save two files under the same zip?
Also on the end the zip file is saved in different location- than base_name
I also find some option with Zipfile library but I don't know how to modify it
import zipfile
with zipfile.ZipFile(zipname,'a') as myzip:
name_file_only=filename.split(os.sep)[-1]
myzip.write(filename,name_file_only)
os.remove(filename)
I will be grateful for any tips and solution.