我可能没说清楚,我贴一下代码吧。
我的目的是搜索我要打开的程序的exe,然后打开这个程序。windows的搜索太慢,所以我调用everything来搜索,现在的问题是我搜索到的结果有三个,我怎么选择我需要的那个结果
例如我搜索到了这三个路径,我想选择第二个打开
E:\firefox download\oss-aliyun-1.2.1.0.exe
D:\Program Files\oss-browser-win32-x64\oss-browser.exe
E:\Work\ALIYUN\software\ossutil64\ossutil64.exe
from ctypes import windll,byref,create_unicode_buffer
#以下代码调用everything-SDK
def search_files(file):
Search = windll.LoadLibrary(r'E:\python\test\Everything-SDK\dll\everything64.dll')
strBuff = create_unicode_buffer(255)
Search.Everything_SetSearchW(file)
Search.Everything_QueryW(True)
Results = Search.Everything_GetNumResults()
for index in range(Results):
Search.Everything_GetResultFullPathNameW(index,byref(strBuff),len(strBuff))
yield strBuff.value
del Search
del strBuff
#执行搜索
a = input("请输入程序名:")
if __name__=='__main__':
for file in search_files(a):
#path = file
#b = os.path.dirname(path) #返回文件路径,不显示程序名
#print (b)
if file.endswith('.exe'): #判断名称的结尾是否是.exe
print (file)
|