Oct-06-2022, 02:02 PM
Hi
I am new to this forum and new user of python.
I have list of files and directories (contain files and subdirectories) in CSV file. The file name and main directory name is same in each CSV row . I want to make the zip file of file and directory in each row having zip file name as file name.
csv file:
Question:
I want to make zip file of each row and corresponding directory as one zip file having name as file name in 1st column
Could you please anyone suggest, how can i process further.
Many Thanks
Nasir
I am new to this forum and new user of python.
I have list of files and directories (contain files and subdirectories) in CSV file. The file name and main directory name is same in each CSV row . I want to make the zip file of file and directory in each row having zip file name as file name.
csv file:
Output:File Directory
C:\\Users\\XYZ\\Desktop\\TEST\\\TEST.abc C:\\Users\\XYZ\\Desktop\\TEST\\\TEST.XYZ
C:\\Users\\XYZ\\Desktop\\TEST\\\TEST1.abc C:\\Users\\XYZ\\Desktop\\TEST\\\TEST1.XYZ
C:\\Users\\XYZ\\Desktop\\TEST\\\TEST2.abc C:\\Users\\XYZ\\Desktop\\TEST\\\TEST2.XYZ
C:\\Users\\XYZ\\Desktop\\TEST\\\TEST3.abc C:\\Users\\XYZ\\Desktop\\TEST\\\TEST3.XYZ
Python code:path = "C:\\Users\\XYZ\\Desktop\\TEST.csv" ## CSV file which contain listing of files and directory path df = pd.read_csv(path) for index, row in df.iterrows(): target1 = row.File target2 =row.Directory with ZipFile("TEST.zip", "w") as newzip: newzip.write(target1) newzip.write(target2)It gives only the zip file of last file and directory which is TEST3
Question:
I want to make zip file of each row and corresponding directory as one zip file having name as file name in 1st column
Could you please anyone suggest, how can i process further.
Many Thanks
Nasir