importosdefsearch(s,path=os.path.abspath('.')):forzinos.listdir(path):ifos.path.isdir(z):print'Currnet:',pathpath2=os.path.join(path,z)print'future:',path2search(s,path2)...
import os
def search(s,path=os.path.abspath('.')):
for z in os.listdir(path):
if os.path.isdir(z):
print 'Currnet:',path
path2=os.path.join(path,z)
print 'future:',path2
search(s,path2)
elif os.path.isfile(z):
if s in z:
print os.path.join(path,z)
search(raw_input('Please enter a string:'))
执行结果:
PS D:\programfiles\python2.7> python err.py
Please enter a string:e
Crrunet: D:\programfiles\python2.7
fetural: D:\programfiles\python2.7\DLLs
Crrunet: D:\programfiles\python2.7
fetural: D:\programfiles\python2.7\Doc
D:\programfiles\python2.7\err.py
Crrunet: D:\programfiles\python2.7
fetural: D:\programfiles\python2.7\include
Crrunet: D:\programfiles\python2.7
fetural: D:\programfiles\python2.7\Lib
Crrunet: D:\programfiles\python2.7
fetural: D:\programfiles\python2.7\libs
D:\programfiles\python2.7\mydict_test.py
D:\programfiles\python2.7\mydict_test.pyc
D:\programfiles\python2.7\python.exe
D:\programfiles\python2.7\pythonw.exe
D:\programfiles\python2.7\Removepywin32.exe
Crrunet: D:\programfiles\python2.7
fetural: D:\programfiles\python2.7\Scripts
Crrunet: D:\programfiles\python2.7
fetural: D:\programfiles\python2.7\tcl
Crrunet: D:\programfiles\python2.7
fetural: D:\programfiles\python2.7\Tools
Crrunet: D:\programfiles\python2.7\Tools
fetural: D:\programfiles\python2.7\Tools\Scripts
D:\programfiles\python2.7\w9xpopen.exe
为什么search里面的search没能成功的执行?
展开