简体   繁体   中英

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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM