Monitor folder and zip files for given extension if beyond a given number
import time
import os
import subprocess
import uuid
import sys
if len(sys.argv) < 4 :
print "Usage: zipUtil <path> <numFiles> <userName>"
sys.exit(1)
print sys.argv
path=sys.argv[1]
print path
num=int(sys.argv[2])
print num
user = sys.argv[3]
print user
while 1 == 1:
text_files = [f for f in os.listdir(path) if (f.endswith('.cov') and not f.startswith('srm'))]
print "Files found : " , text_files
if(len(text_files)>num):
print "Number of files greater than " + str(num)
filename = user + "_" + str(uuid.uuid4())+ ".zip"
command = ["zip.exe", filename]
command.extend(text_files)
print command
subprocess.check_call(command)
command = ["cmd.exe","/c","del"]
command.extend(text_files)
print command
subprocess.check_call(command)
else:
print "Not enough files"
print "Sleeping for 20 secs"
time.sleep(20)