Answer the question
In order to leave comments, you need to log in
How to make it so that after recursively bypassing folders and files, the contents inside the found file could be output to the console?
the program does a recursive traversal of folders and files, but I can not display the contents of the file that the program found in the console
import os
path = 'D:\\projects\\python\\folder_obhod'
print(path)
def obhodFile(path, level=1):
print('Level=', level, 'Content:', os.listdir(path))
for i in os.listdir(path):
if os.path.isdir(path+'\\'+i):
obhodFile(path + '\\' + i, level+1)
print('Спускаемся', path + '\\' + i)
if os.path.isfile(path+'\\'+i):
file = os.path.isfile(path+'\\'+i)
read = open(file, 'r')
print(read)
obhodFile(path)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question