Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. import glob
  2.  
  3. # Your custom code.  This is a list of strings.  The commas separate
  4. # the individual strings, and the \ means "continue on the next line"
  5. tylersCode = [\
  6.     "blahblahblah",\
  7.     "my name is Tyler",\
  8.     "and I don't know how to program",\
  9.     "just kidding, haha."]
  10.  
  11. # The number of lines to skip in each file before inserting your custom code
  12. numberOfLines = 3
  13.  
  14. # The extension of all the files you want to fix.
  15. extension = '*.txt'
  16.  
  17. # The filepath folder to look in
  18. folderpath = 'C:\\path\\to\\the\\files\\'
  19.  
  20.  
  21. toProcess = glob.glob(folderpath+extension)
  22.  
  23. for each in toProcess:
  24.     fileRead = open(each)
  25.    
  26.     lines = []
  27.     for line in fileRead:
  28.         lines.append(line)
  29.     fileRead.close()
  30.  
  31.     fileWrite = open(each, 'w')
  32.     fileWrite.writelines(lines[:numberOfLines])
  33.     fileWrite.writelines(yourCode)
  34.     fileWrite.writelines(lines[numberOfLines:])
  35.     fileWrite.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement