Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Part 1 walks the directory. Part 2 extracts the text I want. Each part works fine independently but all together it gives an error . I tried the code below but I get an unexpected indent error at the line starting: with open (fname)
- import os
- import re
- #walk the directory ree
- rootDir = '.'
- for dirName, subdirList, fileList in os.walk(rootDir):
- print('Found directory: %s' % dirName)
- for fname in fileList:
- print('\t%s' % fname)
- #extract the text from each file
- with open(fname) as infile, open('out.txt', 'a') as outfile:
- full=infile.read().replace('\n','')
- text = ''.join(re.findall(r"START(.+?)END", full))
- outfile.write(text)
- infile.close()
- outfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement