Advertisement
Guest User

Untitled

a guest
May 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import glob, os, csv
  4.  
  5. def inplace_change(filename, old_string, new_string):
  6. s=open(filename).read()
  7. if old_string in s:
  8. print 'Changing "{old_string}" to "{new_string}"'.format(**locals())
  9. s=s.replace(old_string, new_string)
  10. f=open(filename, 'w')
  11. f.write(s)
  12. f.flush()
  13. f.close()
  14. text_file = open("Process_worked.txt", "a")
  15. text_file.write("%s;%s;%sn" %(worfile,old_string,new_string))
  16. text_file.close()
  17. else:
  18. print 'No occurances of "{old_string}" found.'.format(**locals())
  19. text_file = open("Process_notfound.txt", "a")
  20. text_file.write("%s;%s;%sn" %(worfile,old_string,new_string))
  21. text_file.close()
  22.  
  23. #worfile='Bruce Workspace_13-06-2008.wor'
  24. csvfile='File_Locations.csv'
  25. special='Open Table "'
  26. wor_list=glob.glob('*.wor')
  27.  
  28. for worfile in wor_list:
  29. print worfile
  30. r = csv.DictReader(open(csvfile, "rt"), dialect="excel")
  31. for row in r:
  32. old_string=row['Existing File Path']+row['File Name']
  33. new_string=row['New File Path']+'\'+row['New Name']
  34. print old_string, new_string
  35. inplace_change(worfile,old_string,new_string)
  36. inplace_change(worfile,row['File Name'],row['New Name'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement