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
  Extracting data from bank statement PDFs (Accountant) a4avinash 4 5,492 Feb-27-2025, 01:53 PM
Last Post: griffinhenry
  Confused by the different ways of extracting data in DataFrame leea2024 1 684 Aug-17-2024, 01:34 PM
Last Post: deanhystad
  How to add multi-line comment section? Winfried 2 1,359 Jun-04-2024, 07:24 AM
Last Post: Gribouillis
  Extracting the correct data from a CSV file S2G 6 1,816 Jun-03-2024, 04:50 PM
Last Post: snippsat
  Trying to generating multiple json files using python script dzgn989 4 2,249 May-10-2024, 03:09 PM
Last Post: deanhystad
  Is it possible to extract 1 or 2 bits of data from MS project files? cubangt 8 3,658 Feb-16-2024, 12:02 AM
Last Post: deanhystad
  python convert multiple files to multiple lists MCL169 6 3,293 Nov-25-2023, 05:31 AM
Last Post: Iqratech
Question remove all comment ? SpongeB0B 7 9,615 Oct-27-2023, 05:40 PM
Last Post: deanhystad
  splitting file into multiple files by searching for string AlphaInc 2 2,757 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  script to calculate data in csv-files ledgreve 0 2,347 May-19-2023, 07:24 AM
Last Post: ledgreve

Forum Jump:

User Panel Messages

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