Discuss / Python / 第二题我的解答

第二题我的解答

Topic source

lubang03

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

我的解答

import os

def findFile(path,key, rootPath): if os.path.isdir(path): for item in os.listdir(path): findFile(os.path.join(path,item), key,rootPath) elif os.path.isfile(path): fileName = os.path.split(path)[-1] if fileName.find(key) != -1: print("The absolute path is:", path) print("The relative path is:", os.path.relpath(path, rootPath))

rootPath = "." //可以是指定的路径 key = "xxxx" //指定的关键字 findFile(rootPath, key, rootPath)


  • 1

Reply