python 解压zip文件脚本

释放双眼,带上耳机,听听看~!

Windows Server 2008 R2 系统自带的Powershell脚本是2.0版本,无法调用本地一些解压缩软件解压zip文件,但是可以调用python,具体的解压命令如下所示


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1# -*- coding: utf-8 -*-.
2import os
3import shutil
4import zipfile
5from os.path import join, getsize
6
7def unzip_file(zip_src, dst_dir):
8    r = zipfile.is_zipfile(zip_src)
9    if r:    
10        fz = zipfile.ZipFile(zip_src, 'r')
11        for file in fz.namelist():
12            fz.extract(file, dst_dir)      
13    else:
14        print('This is not zip')
15
16def remove_files():
17    if os.path.exists("d:\\UNZIP\\index.html"):
18        os.remove("d:\\UNZIP\\index.html")
19        shutil.rmtree('D:\\UNZIP\\static',ignore_errors=True)
20    else:
21        print("error")
22remove_files()
23unzip_file("d:\\UNZIP\\dist.zip","d:\\UNZIP")
24
25

给TA打赏
共{{data.count}}人
人已打赏
安全技术

C/C++内存泄漏及检测

2022-1-11 12:36:11

病毒疫情

老“糖友”看病的三个新体验

2020-3-27 8:12:00

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索