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:
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
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:1 2 3 4 5 6 7 8 9 10 |
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) |
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
Larz60+ write Oct-07-2022, 09:22 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Note: Output tags also work well for input data
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Note: Output tags also work well for input data