File: changeString.py

package info (click to toggle)
stopt 5.12%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,860 kB
  • sloc: cpp: 70,456; python: 5,950; makefile: 72; sh: 57
file content (29 lines) | stat: -rw-r--r-- 788 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sys
import os
import fileinput
import re

stringToReplace  = sys.argv[1]
print " stringToReplace " , stringToReplace
newString  = sys.argv[2]
print " newString " , newString
extention =sys.argv[3]
print " extention " , extention

pathh = ['../StOpt', '../test']
for xpath in pathh:
    for path, subdirs, files   in os.walk(xpath):
        for name in files:
            if name.endswith("."+extention):
                print " file " , name
                fp =open(path+"/"+name.rstrip(),'r')   
                dlines = fp.readlines()    
                fp.close()
                fp =open(path+"/"+name.rstrip(),'w')  
                for l in dlines:  
                    l= re.sub(stringToReplace,newString,l)
                    fp.write(l)
                fp.close()