Created
April 21, 2015 14:47
-
-
Save diverted247/44c027dde6b5ecf1674c to your computer and use it in GitHub Desktop.
Walking paths, delete all .gz files, the compress all files to .gz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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