Discuss / Python / 练习2

练习2

Topic source
def searchFlie(path, str):
    for i in os.listdir(path): # 遍历目录列表
        thisPath = os.path.join(path, i) # 获取当前绝对路径
        if os.path.isfile(thisPath) and str in i: # 判断路径对应的是文件,并且搜索字符串是否包含在路径中
            print(thisPath)
        elif os.path.isdir(thisPath): # 判断路径对应的是目录
            searchFlie(thisPath, str) # 递归


searchFlie(os.path.abspath('.'), '1')

  • 1

Reply