Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import glob, os, csv
- def inplace_change(filename, old_string, new_string):
- s=open(filename).read()
- if old_string in s:
- print 'Changing "{old_string}" to "{new_string}"'.format(**locals())
- s=s.replace(old_string, new_string)
- f=open(filename, 'w')
- f.write(s)
- f.flush()
- f.close()
- text_file = open("Process_worked.txt", "a")
- text_file.write("%s;%s;%sn" %(worfile,old_string,new_string))
- text_file.close()
- else:
- print 'No occurances of "{old_string}" found.'.format(**locals())
- text_file = open("Process_notfound.txt", "a")
- text_file.write("%s;%s;%sn" %(worfile,old_string,new_string))
- text_file.close()
- #worfile='Bruce Workspace_13-06-2008.wor'
- csvfile='File_Locations.csv'
- special='Open Table "'
- wor_list=glob.glob('*.wor')
- for worfile in wor_list:
- print worfile
- r = csv.DictReader(open(csvfile, "rt"), dialect="excel")
- for row in r:
- old_string=row['Existing File Path']+row['File Name']
- new_string=row['New File Path']+'\'+row['New Name']
- print old_string, new_string
- inplace_change(worfile,old_string,new_string)
- inplace_change(worfile,row['File Name'],row['New Name'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement