Created
December 14, 2015 13:12
-
-
Save ZiTAL/86a5df6dba63823c2aea to your computer and use it in GitHub Desktop.
Remove  from files
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys, os, re | |
if(len(sys.argv)<2): | |
print 'Errorea: Karpeta argumentu bidez sartu' | |
sys.exit() | |
else: | |
dir = sys.argv[1] | |
# fitxategien zerrenda | |
file_list = [] | |
def scandir(dir): | |
if os.path.isdir(dir): | |
dir_list = os.listdir(dir) | |
for f in dir_list: | |
path = os.path.join(dir, f) | |
if os.path.isfile(path): | |
file_list.append(path) | |
elif os.path.isdir(path): | |
scandir(path) | |
# fitxategien zerrenda hartu | |
scandir(dir) | |
print "Fitxategi hauetatik  kentzen:" | |
regex = re.compile("", re.MULTILINE) | |
for f in file_list: | |
size = os.path.getsize(f) | |
content = open(f).read(size) | |
if(regex.search(content)): | |
print f | |
replace = regex.sub('', content) | |
file = open(f, 'w') | |
file.write(replace) | |
file.close() | |
print "Eginda" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment