'I want to use Python to unzip the zip file and save it in each folder.?
would like to create each folder and store the data to decompress the folder.
Like the picture.

this is my code
for path in glob.glob(curdir + '/data/*.zip'):
with zipfile.ZipFile(path) as zfile:
zfile.extractall(os.path.dirname(path))
I'm curious about how to change the contents of zfile.extractall(?) here.
Solution 1:[1]
Remove only .zip from path - ie.
zfile.extractall( path.replace('.zip', '') )
or
zfile.extractall( path.rsplit('.', 1)[0] )
zfile.extractall( os.path.splitext(path)[0] )
Full code:
#import os
import glob
import zipfile
curdir = '.'
for path in glob.glob(curdir + '/data/*.zip'):
with zipfile.ZipFile(path) as zfile:
zfile.extractall( path.replace('.zip', '') )
#zfile.extractall( path.rsplit('.', 1)[0] )
#zfile.extractall( os.path.splitext(path)[0] )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
