Sep-10-2018, 10:33 AM
(This post was last modified: Sep-10-2018, 10:34 AM by SoulsKeeper.)
(Sep-09-2018, 12:42 PM)snippsat Wrote: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?(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 forgotr
.
ThenC:\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 useos.path.join()
to create a absolute path to .zip files.
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))