![]() |
Making Zip file of a file and Directory - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Making Zip file of a file and Directory (/thread-38384.html) |
Making Zip file of a file and Directory - Nasir - Oct-06-2022 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: 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 RE: Making Zip file of a file and Directory - bowlofred - Oct-06-2022 Looks like you're opening a new zipfile (overwriting any previous one) inside your for loop. I think you want to open the zipfile outside the for loop and only do the write() inside. But why is column2 titled "directory"? Those entries don't look like directories to me. RE: Making Zip file of a file and Directory - Nasir - Oct-07-2022 That is just a sample CSV file, however these are actually a directory names |