Skip to content

Instantly share code, notes, and snippets.

@diverted247
Created April 21, 2015 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diverted247/44c027dde6b5ecf1674c to your computer and use it in GitHub Desktop.
Save diverted247/44c027dde6b5ecf1674c to your computer and use it in GitHub Desktop.
Walking paths, delete all .gz files, the compress all files to .gz
import os
import gzip
def process( directory ):
for dirpath , dnames , fnames in os.walk( directory ):
for f in fnames:
if f.endswith( '.gz' ):
print( 'Delete:' + f )
os.remove( dirpath + os.sep + f )
for dirpath , dnames , fnames in os.walk( directory ):
for f in fnames:
if f.startswith( '.' ):
print( 'ignore:' + dirpath + os.sep + f )
continue
print( 'gzip:' + dirpath + os.sep + f )
file_input = open( dirpath + os.sep + f , 'rb')
file_output = gzip.open( dirpath + os.sep + f + '.gz', 'wb')
file_output.writelines( file_input )
file_output.close()
file_input.close()
#paths to process
process( './static' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment