Discuss / Python / 编写一个程序,能在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径

编写一个程序,能在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径

Topic source

listdir=[x for x in os.listdir('.') if os.path.isdir(x)]

def getfilepy():

for d in listdir:

for x in os.listdir(d):

if os.path.isfile(x) and os.path.splitext(x)[1]=='.py':

print(x)

print(getfilepy())

print(os.path.abspath(x))


  • 1

Reply