osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to access a folder inside a zip file


Hello!

I'm a newbie in python and I was trying to access a folder inside a zip file and I also have issues with relative and absolute path. Thks in advance.

In projects there a lot of urls (i'll read them later one by one and store them in a list/array so that I could work with it easily)

here is the path:  home/name/tutorial/prof/ks.zip/projects

should I use 

file_name = "ks.zip" 

or

file_location = os.path.dirname(os.path.abspath(__file__))
#print(file_location)  ?



# specifying the zip file name
file_name = "ks.zip"

 # opening the zip file in READ mode
with ZipFile(file_name, 'r') as zip:

   # printing all the contents of the zip file
   zip.printdir()

    # extracting all the files
   print('Extracting all the files now...')
   zip.extractall()
   print('Done!')