Guest User

Untitled

a guest
Oct 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import shutil
  2. import os
  3. import re
  4.  
  5. try:
  6. shutil.move("./xhtml/nav.xhtml", ".")
  7.  
  8. with open('nav.xhtml', 'r') as f : #read the file and modify nav.xhtml link
  9. filedata = f.read()
  10. filedata = filedata.replace(r'href="', r'href="xhtml/')
  11.  
  12. with open('nav.xhtml', 'w') as f : #reopen the file and write the replaced contents
  13. f.write(filedata)
  14.  
  15. except shutil.Error: #my exercise :)
  16. print("The nav.xhtml was already moved. First phase was skipped.")
  17.  
  18.  
  19. with open('package.opf', 'r') as f : #modify package.opf links
  20. filedata = f.read()
  21. filedata = filedata.replace(r"xhtml/nav.xhtml", r"nav.xhtml")
  22.  
  23. with open('package.opf', 'w') as f :
  24. f.write(filedata)
Add Comment
Please, Sign In to add comment