Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import glob
- # Your custom code. This is a list of strings. The commas separate
- # the individual strings, and the \ means "continue on the next line"
- tylersCode = [\
- "blahblahblah",\
- "my name is Tyler",\
- "and I don't know how to program",\
- "just kidding, haha."]
- # The number of lines to skip in each file before inserting your custom code
- numberOfLines = 3
- # The extension of all the files you want to fix.
- extension = '*.txt'
- # The filepath folder to look in
- folderpath = 'C:\\path\\to\\the\\files\\'
- toProcess = glob.glob(folderpath+extension)
- for each in toProcess:
- fileRead = open(each)
- lines = []
- for line in fileRead:
- lines.append(line)
- fileRead.close()
- fileWrite = open(each, 'w')
- fileWrite.writelines(lines[:numberOfLines])
- fileWrite.writelines(yourCode)
- fileWrite.writelines(lines[numberOfLines:])
- fileWrite.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement