Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Created December 14, 2015 13:12
Show Gist options
  • Save ZiTAL/86a5df6dba63823c2aea to your computer and use it in GitHub Desktop.
Save ZiTAL/86a5df6dba63823c2aea to your computer and use it in GitHub Desktop.
Remove  from files
#!/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 &#65279; kentzen:"
regex = re.compile("&#65279;", 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