
import sys
def filelist(path,r,f):
"""
function to find the directions and files in the given direction
according to your parameters,fileonly or not,recursively find or not.
"""
file_list = []
os.chdir(path)
filename = os.listdir(path)
if len(filename) == 0:
os.chdir(os.pardir)
return filename
if r == 1:##
if f == 0:# r = 1, recursively find directions and files. r = 0 otherwise.
for name in filename: # f = 1, find files only, f = 0,otherwise.
if os.path.isdir(name): ##
file_list.append(name)
name = os.path.abspath(name)
subfile_list = filelist(name,r,f)
for n in range(len(subfile_list)):
subfile_list[n] = '\t'+subfile_list[n]
file_list += subfile_list
else:
file_list.append(name)
os.chdir(os.pardir)
return file_list
elif f == 1:
for name in filename:
if os.path.isdir(name):
name = os.path.abspath(name)
subfile_list = filelist(name,r,f)
for n in range(len(subfile_list)):
subfile_list[n] = '\t'+subfile_list[n]
file_list += subfile_list
else:
file_list.append(name)
os.chdir(os.pardir)
return file_list
else:
print 'Error1'
elif r == 0:
if f == 0:
os.chdir(os.pardir)
return filename
elif f == 1:
for name in filename:
if os.path.isfile(name):
file_list.append(name)
os.chdir(os.pardir)
return file_list
else:
print 'Error2'
else:
print 'Error3'
'''
f = 0:list all the files and folders
f = 1:list files only
r = 1:list files or folders recursively,all the files and folders in the current direction andsubdirection
r = 0:only list files or folders in the current direction,not recursively
as for RE to match certern file or dirction,you can write yourself, it is easier than the function above.Just use RE to match the result,if match,printelse,pass
"""
1:
for name in li:print dict[name]
2:
name="xxx"for i in workes:
if i["Name"]=name:
for x in i:
print x,":",i[x]
else:
print "name not find "
可能帮不上忙。但别的语言有现成的。用java 的 solr做搜索,索引,分词。只需要配置xml,不用写代码。然后加上前端页面搜索就完成了。用python的scrapy可以做爬虫。你的需求我感觉简单做,都不需要索引,直接查数据库。模糊查询还有一个java的nutch,几乎不用写代码,直接爬虫+索引+界面 一套都实现好了,什么高亮,快照都有,直接用。不知道你能出多少钱?欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)