Python Forum
Help extracting comment data from multiple zip files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help extracting comment data from multiple zip files
#11
(Sep-09-2018, 12:42 PM)snippsat Wrote:
(Sep-09-2018, 12:21 PM)SoulsKeeper Wrote: solved it by using the the other slash(/)
You had it right in first post then you forgot r.
Then C:\U will give unicodeescape error.
path = r'C:\Users\user\Desktop\archives'
# Other way also work
path = 'C:/Users/user/Desktop/archives'
Change to folder you have zip in.
import os
from zipfile import ZipFile

path = r'C:\Users\user\Desktop\archives'
zipfiles = [f for f in os.listdir(path)]
for zfile in zipfiles:
    print(f"Opening: {zfile}")
    os.chdir(path) # Change to path folder
    with ZipFile(zfile, 'r') as testzip:
        print(testzip.comment)
If not changing to folder with .zip files has to use os.path.join() to create a absolute path to .zip files.
sorry for the delay, i already solved it but now i realize that i need it for Rar files and not Zip files, what do i need to change to get the same effect?

import unicodedata

from zipfile import ZipFile
rootFolder = u"C:/Users/user/Desktop/archives/"

zipfiles = [os.path.join(rootFolder, f) for f in os.listdir(rootFolder)]
for zfile in zipfiles:
    print("Opening: {}".format(zfile))
    with ZipFile(zfile, 'r') as testzip:
        print(testzip.comment) # comment for entire zip
        l = testzip.infolist() #list all files in archive
        for finfo in l:
            # per file/directory comments
            print("{}:{}".format(finfo.filename, finfo.comment))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to add multi-line comment section? Winfried 1 220 Mar-24-2024, 04:34 PM
Last Post: deanhystad
  Is it possible to extract 1 or 2 bits of data from MS project files? cubangt 8 1,072 Feb-16-2024, 12:02 AM
Last Post: deanhystad
  python convert multiple files to multiple lists MCL169 6 1,568 Nov-25-2023, 05:31 AM
Last Post: Iqratech
Question remove all comment ? SpongeB0B 7 1,380 Oct-27-2023, 05:40 PM
Last Post: deanhystad
  splitting file into multiple files by searching for string AlphaInc 2 909 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  script to calculate data in csv-files ledgreve 0 1,113 May-19-2023, 07:24 AM
Last Post: ledgreve
  Merging multiple csv files with same X,Y,Z in each Auz_Pete 3 1,183 Feb-21-2023, 04:21 AM
Last Post: Auz_Pete
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 975 Feb-15-2023, 05:34 PM
Last Post: zsousa
  Find duplicate files in multiple directories Pavel_47 9 3,146 Dec-27-2022, 04:47 PM
Last Post: deanhystad
  Extracting Data into Columns using pdfplumber arvin 17 5,600 Dec-17-2022, 11:59 AM
Last Post: arvin

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020