-
Notifications
You must be signed in to change notification settings - Fork 11
/
zipEm.py
55 lines (48 loc) · 1.75 KB
/
zipEm.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 12 11:30:50 2017
@author: Rdebbout
"""
import os
from os.path import basename
import zipfile
from Tkinter import Tk
from tkFileDialog import askdirectory
Tk().withdraw()
def main():
home = askdirectory(title='Select directory where CSVs are stored...\n\
A directory named \'zips\' will be created if not there\n\
Only zips that\ don\'t exist yet will be made.',initialdir=os.getcwd())
if not os.path.exists('%s/zips' % home):
os.mkdir('%s/zips' % home)
for f in os.listdir(home):
if '.csv' in f:
if not f.count('.') ==2:
fn = f.split('.')[0]
if f.count('.') ==2:
fn = f.split('.')[0] + '.' + f.split('.')[1]
if not os.path.exists('%s/zips/%s.zip' % (home,fn)):
print('zipping...... %s') % fn
zf = zipfile.ZipFile('%s/zips/%s.zip' % (home,fn), mode='w')
# zf.write('%s/%s'%(home,f),
# compress_type=zipfile.ZIP_DEFLATED)
zf.write('%s/%s'%(home,f), basename('%s/%s'%(home,f)),
compress_type=zipfile.ZIP_DEFLATED)
zf.close()
#############################################################################
if __name__ =='__main__':
main()
#vpus = r'L:\Priv\CORFiles\Geospatial_Library\Data\Project\StreamCat\FTP_Staging\StreamCat\HydroRegions'
#states = r'L:\Priv\CORFiles\Geospatial_Library\Data\Project\StreamCat\FTP_Staging\StreamCat\States'
#v_uni = []
#for f in os.listdir(vpus):
# if '.csv' in f:
# v_uni.append(f.split('.')[0].split('Region')[0])
#
#
#s_uni = []
#for f in os.listdir(states):
# if '.csv' in f:
# s_uni.append(f.split('.')[0][:-2])
#
#print set(v_uni)-set(s_uni)