想用python实现获取一个文件夹内所有txt文件第二行内容的功能

代码如下:


#从文件夹中文件的同一位置提取信息
import os
import linecache
N = input("请输入文件夹名称:")
for root, dirs, files in os.walk(N,topdown=False):
    for name in files:
        txt = linecache.getline(name,3)
        print(txt)
#input("请按任意键退出")

但是结果没有输出
请输入文件夹名称:6

import os
import linecache

N = input("请输入文件夹名称:")
for root, dirs, files in os.walk(N, topdown=False):
for name in files:
name = N+'\'+name
txt = linecache.getline(name, 3)
这是win系统下的,name和N这个文件夹都要是路径,光一个名称找不到
print(txt)

第二行内容应该是 txt = linecache.getline(name,2)