I have directories structure:
--- main_dir
------ aaa
--------subaaa
----------file
------ xxx
--------subxxx
----------file
------ 111
--------sub111
----------file
etc.
All directories has different names but FILE has the same name. Every FILE has three lines. My question is how to read these three lines frome every FILE in the fastest way?
I have written code that search for FILEs. But still do not know how to read all of them. Check this out:
import os
def list_files(dir):
r = []
for root, dirs, files in os.walk(dir):
for name in files:
r.append(os.path.join(root, name))
return r, print(r)
list_files('some_path)
I want to achieve something like that:
import os
def list_files(dir):
r = []
for root, dirs, files in os.walk(dir):
for name in files:
r.append(os.path.join(root, name))
return r, print(r)
with open(r[*]) as f: #this is the question
f.readlines() #how to read all of the files
list_files('some_path)