Skip to content

Instantly share code, notes, and snippets.

@cnsoft
Created May 24, 2013 08:13
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 cnsoft/5642049 to your computer and use it in GitHub Desktop.
Save cnsoft/5642049 to your computer and use it in GitHub Desktop.
import os
filters = ['.cpp','.h','.py','.hpp','.ipp','.sln','.vcproj','.mak']
filters.extend(['.c','python','Makefile','php'])
#filters = ['python']
#filters = ['*']
if os.name == 'posix':
FOLDER_FIX = '/'
else:
FOLDER_FIX = "\\"
def checkDirFilter(dir):
global filters
if filters == ['*']:
return True
for f in filters:
if dir == f or dir.find(f) >0:
return True
return False
def doReplace(filename):
f1 = open(filename,'r')
f2 = open(filename+'_','w')
for line in f1.readlines():
newline = line.replace('\r','\n')
f2.write(newline)
f2.close()
f1.close()
os.system('xcopy %s_ %s /y'%(filename,filename))
os.system('del %s_ /F'%(filename))
print 'Process %s ok'%filename
def enum_exe(arg,dirname,names):
for name in names:
file1 = dirname+ FOLDER_FIX +name
if not dirname.find('.svn') > 0 and checkDirFilter(file1):
if name.find('myReplace.py') < 0 or name.find('_') <0:
print 'To process file %s'%file1
if os.path.exists(file1) and os.path.isfile(file1):
#if file1.find('python') >0: #only procss that folder
doReplace(file1)
def convertWin():
os.path.walk(".\\fantasydemo",enum_exe,())
convertWin()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment