def search(s , str):
for subdir in os.listdir(s):
if os.path.isdir(subdir):
search(os.path.join(s,subdir),str)
if os.path.isfile(subdir):
if subdir.find(str)!=-1:
print os.path.join(os.path.abspath(s),subdir)
def test_search():
if len(sys.argv)!=2:
print '请输入要查找的字符串!'
return -1
else:
s = '.'
search(s,sys.argv[1])
return 1
liadbiz
-- coding: utf-8 --
'test io search' author = 'liadhiz'
import os import sys
def search(s , str): for subdir in os.listdir(s): if os.path.isdir(subdir): search(os.path.join(s,subdir),str) if os.path.isfile(subdir): if subdir.find(str)!=-1: print os.path.join(os.path.abspath(s),subdir)
def test_search(): if len(sys.argv)!=2: print '请输入要查找的字符串!' return -1 else: s = '.' search(s,sys.argv[1]) return 1
if name=='main': test_search()