Discuss / Python / 第二题

第二题

Topic source

Reva龙舞

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

使用递归方法获取复合条件文件夹 需要输入2个参数:路径和关键字 import os root = input('please input root:') keyword = input('please input keyword:')

def getfile(path,key): if (key in os.path.split(path)[1]): print("result: "+path)

def iter(road): for x in os.listdir(road): if os.path.isfile(os.path.join(road,x)): getfile(os.path.join(road,x),keyword) else: iter(os.path.join(road,x)+'\') iter(root)


  • 1

Reply