Discuss / Python / 终于做出来了,超有成就感!!看别人做的我发现很多人都没有用相对路径。

终于做出来了,超有成就感!!看别人做的我发现很多人都没有用相对路径。

Topic source

浴火化影

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

import os def search(x,dir): for thing in os.scandir(dir): newpath=os.path.join(dir,thing.name) if os.path.isfile(thing): if x in thing.name: print(os.path.relpath(newpath,a)) #global elif os.path.isdir(thing): search(x,newpath)

a=os.getcwd() b=input('please input what you want to find:') search(b,a)

不错,学习了

然而复制过来却不能用


  • 1

Reply