I want to extract data from multiple files nested within subfolders.
e.g. folder structure
A/B/C/D.dat
A/B/E/F.dat
A/B/G/H.dat
The code I came up with is:
import os
values = 2
doc = []
rootdir = 'C:/A/B'
for subdir, dirs, files in os.walk(rootdir):
for file in files:
if file.endswith('.dat'):
with open (file, 'rt') as myfile:
current_line = 0
for mylines in myfile:
if current_line == values:
doc.append()
break
current_line += 1
continue
print(doc)
Error I struggle to solve:
...with open (file, 'rt') as myfile:
IOError: [Errno 2] No such file or directory: 'D.dat'