F
F
Foxrey2020-08-18 21:37:12
Python
Foxrey, 2020-08-18 21:37:12

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

1 answer(s)
S
soremix, 2020-08-18
@Foxrey

Read the file, then output the content
read.read()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question