1 |
86eb951b
|
Jim Regetz
|
import os, fnmatch, zipfile, datetime
|
2 |
|
|
|
3 |
|
|
outpath = '//I/NCEAS/topo/incoming/srtmv41'
|
4 |
|
|
inpath = '//I/NCEAS/SRTM_90m_ASCII_v4.1'
|
5 |
|
|
logname = outpath + '/unzip.log'
|
6 |
|
|
logfile = open(logname, 'a')
|
7 |
|
|
logfile.write('Start unziptiles.py at ' + str(datetime.datetime.today()) + '\n')
|
8 |
|
|
|
9 |
|
|
nprocessed = 0
|
10 |
|
|
nerrors = 0
|
11 |
|
|
|
12 |
|
|
try:
|
13 |
|
|
|
14 |
|
|
for filename in os.listdir(inpath):
|
15 |
|
|
fullname = inpath + '/' + filename
|
16 |
|
|
if fnmatch.fnmatch(fullname, '*.zip'):
|
17 |
|
|
print fullname
|
18 |
|
|
try:
|
19 |
|
|
zip = zipfile.ZipFile(fullname, 'r')
|
20 |
|
|
for zipi in zip.infolist():
|
21 |
|
|
name = zipi.filename
|
22 |
|
|
if name != 'readme.txt':
|
23 |
|
|
outfilename = outpath + '/' + name
|
24 |
|
|
print outfilename
|
25 |
|
|
if os.path.exists(outfilename):
|
26 |
|
|
print 'done'
|
27 |
|
|
else:
|
28 |
|
|
print 'Process', outfilename
|
29 |
|
|
outfile = open(outfilename, 'w')
|
30 |
|
|
outfile.write(zip.read(name))
|
31 |
|
|
outfile.close()
|
32 |
|
|
nprocessed = nprocessed + 1
|
33 |
|
|
zip.close()
|
34 |
|
|
except Exception, e:
|
35 |
|
|
print str(e)
|
36 |
|
|
logfile.write(str(e) + '\n')
|
37 |
|
|
nerrors = nerrors + 1
|
38 |
|
|
except Exception, e:
|
39 |
|
|
print "Exception:", e.str()
|
40 |
|
|
logfile.write(str(e) + '\n')
|
41 |
|
|
|
42 |
|
|
logfile.write('Processed ' + str(nprocessed) + '\n')
|
43 |
|
|
logfile.write('Errors: ' + str(nerrors) + '\n')
|
44 |
|
|
logfile.write('End unziptiles.py at ' + str(datetime.datetime.today()) + '\n')
|
45 |
|
|
logfile.close()
|