Discuss / Python / 这个代码的错误在哪里?为什么只找到与名字是s的文件但是找不到名字包含s字符的文件呢?

这个代码的错误在哪里?为什么只找到与名字是s的文件但是找不到名字包含s字符的文件呢?

Topic source

狗不理翔

#1 Created at ... [Delete] [Delete and Lock User]
import os

def getFile(path,s):
    for p in os.listdir(path):
        pathname=os.path.join(path,p)
        if os.path.isdir(pathname):
            getFile(pathname,s)
        elif os.path.isfile(pathname) and s in p:
            return pathname

  • 1

Reply