-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunzip_file.py
More file actions
38 lines (36 loc) · 1.21 KB
/
unzip_file.py
File metadata and controls
38 lines (36 loc) · 1.21 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
import zipfile
import os
from osgeo import gdal
lyr = iface.activeLayer()
check_dsm = 0
for sf in lyr.getSelectedFeatures():
check_dsm = 0
if sf['COMPRESSIO'] == 'zip':
print('è uno zip')
dsm_path = sf["P_BASE"] + sf["P_CAMPAGNA"] + sf["P_DSM"]
dsm_name = sf["N_DSM"].split(".")
dsm_f_name = dsm_name[0] + '.' + dsm_name[1].replace( dsm_name[1], 'zip')
print(dsm_f_name)
dsm_pathfile = os.path.join(dsm_path, dsm_f_name)
if zipfile.is_zipfile(dsm_pathfile):
extr = zipfile.ZipFile(dsm_pathfile)
print(len(extr.namelist()))
if len(extr.namelist()) > 0:
extr.extractall(dsm_path)
check_dsm = 1
unzipped = []
for name in extr.namelist():
unzipped.append(name)
print(unzipped)
else:
#check_dsm = 0
print('lo zip è vuoto')
else:
print('non trovo lo zip')
#print(check_dsm)
else:
print(sf['COMPRESSIO'])
if check_dsm == 1:
for rname in unzipped:
dsm_f_path = os.path.join(dsm_path, rname)
os.remove(dsm_f_path)