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.
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] )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.