'FindTool.py -- start at 2014/2/24'
import os
M_MAX_FILES_PER_CAC = 100000
def SaveIndex(search_dirs):
'搜索路径search_dirs,保存在file_name中'
## file_name = search_dirs[0]+'.cac'
output = []
pernum, datanum = 0,0
temp = os.path.realpath(search_dirs) #标准化路径
for root, dirs, files in os.walk(temp):
filenum = len(files)
for i in range(filenum): #存储文件路径
output.append('%s\%s\n' %(root,files[i]))
pernum += 1
if pernum > M_MAX_FILES_PER_CAC:
file_name = temp[0]+'%d.cac'%datanum
open(file_name, 'w').write(''.join(output))
pernum = 0
datanum += 1
del output[:]
file_name = temp[0]+'%d.cac'%datanum
open(file_name, 'w').write(''.join(output))
def FindFile():
'从保存的索引文件中,查找文件'
dirlist = os.listdir(os.curdir)
file_name = []
#fobj = open(file_name, 'r')
findnum = 0
for eachFile in dirlist:
if '.cac' in eachFile:
file_name.append(eachFile)
findnum += 1
if findnum == 0:
return 0
return file_name
#fobj.close()
阅读(1253) | 评论(0) | 转发(0) |