Thursday, September 13, 2012

Compressing a file using gzip

#!/usr/bin/env python
import gzip
import os

sourceFile = raw_input("Please enter the input file to be compressed:")

if (os.path.exists(sourceFile)):
    pass
else:
    print "Sorry, cant find the file! Please check if the filename and path are correct!\n"
    exit(0)

destFile = raw_input("Please enter the output compressed file name:")

file = open(sourceFile,"rb")

compFile = gzip.open(destFile,"wb")

uncoded = file.read()

compFile.write(uncoded)

file.close()

compFile.close()

No comments:

Post a Comment