Discuss / Python / 上一个忘记换自定义查询变量了?

上一个忘记换自定义查询变量了?

Topic source

Exmlyshy

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

<pre> import os def my_find(*s):#可变参数满足递归 #os.chdir(path)更改当前路径为path path=s[0] global relpath if len(s)>1: relpath=s[1] global key key=input('请输入要查询的文件名:\n') for x in os.listdir(path): if os.path.isfile(path+'\'+x) and (key in x):#os.path.splitext(x)[1]==key: print(x) print('relpath:%s'%os.path.relpath(path,relpath))#os.path.relpath(path[,start])获得path相对于start的相对路径 if os.path.isdir(path+'\'+x): my_find(path+'\'+x) path=input('请输入要查询的目录路径:\n') my_find(path,path) </pre>


  • 1

Reply