Everything python API
关键词:pyhthon,py,everything,索引,全盘,磁盘,快速
简单将链接代码封装了一下,便于全盘索引: vidtools
代码使用everything的DLL,并且要求everything在后台运行
EverythingSDK下载地址:vidtools download
注意,32的py需要引用32位的dll,64位用64位的,否则会出现OSError
import ctypes
import datetime
import struct
import psutil
#defines
EVERYTHING_REQUEST_FILE_NAME = 0x00000001
EVERYTHING_REQUEST_PATH = 0x00000002
EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME = 0x00000004
EVERYTHING_REQUEST_EXTENSION = 0x00000008
EVERYTHING_REQUEST_SIZE = 0x00000010
EVERYTHING_REQUEST_DATE_CREATED = 0x00000020
EVERYTHING_REQUEST_DATE_MODIFIED = 0x00000040
EVERYTHING_REQUEST_DATE_ACCESSED = 0x00000080
EVERYTHING_REQUEST_ATTRIBUTES = 0x00000100
EVERYTHING_REQUEST_FILE_LIST_FILE_NAME = 0x00000200
EVERYTHING_REQUEST_RUN_COUNT = 0x00000400
EVERYTHING_REQUEST_DATE_RUN = 0x00000800
EVERYTHING_REQUEST_DATE_RECENTLY_CHANGED = 0x00001000
EVERYTHING_REQUEST_HIGHLIGHTED_FILE_NAME = 0x00002000
EVERYTHING_REQUEST_HIGHLIGHTED_PATH = 0x00004000
EVERYTHING_REQUEST_HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = 0x00008000
class EverythingAPI():
def __init__(self,dll_path):
#dll imports
self.everything_dll = ctypes.WinDLL (dll_path)
self.everything_dll.Everything_GetResultDateModified.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_ulonglong)]
self.everything_dll.Everything_GetResultSize.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_ulonglong)]
self.everything_dll.Everything_GetResultFileNameW.argtypes = [ctypes.c_int]
self.everything_dll.Everything_GetResultFileNameW.restype = ctypes.c_wchar_p
#setup search
self.everything_dll.Everything_SetRequestFlags(EVERYTHING_REQUEST_FILE_NAME | EVERYTHING_REQUEST_PATH | EVERYTHING_REQUEST_SIZE | EVERYTHING_REQUEST_DATE_MODIFIED)
import psutil
def chkEverythingBG(self):
processName = "everything"
for proc in psutil.process_iter(['pid', 'name', 'username']):
try:
if processName.lower() in proc.name().lower():
# process's parent isn't 'services.exe', which indicates the process is not a service
if psutil.Process(proc.pid).parent().name() != 'services.exe':
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
def search(self,keyword):
self.everything_dll.Everything_SetSearchW(keyword)
#execute the query
self.everything_dll.Everything_QueryW(1)
#get the number of results
num_results = self.everything_dll.Everything_GetNumResults()
#create buffers
filename = ctypes.create_unicode_buffer(260)
#show results
res = []
for i in range(num_results):
self.everything_dll.Everything_GetResultFullPathNameW(i,filename,260)
fullpath = ctypes.wstring_at(filename)
res.append(fullpath)
return res
假如上诉文件保存为eapi.py
import eapi
dll_path = "Everything32.dll"
ea = eapi(dll_path)
# 检查everything是否后台运行
if ea.chkEverythingBG() != True:
print("错误:Everything 未在后台运行")
exit(1)
# 执行查询
res = ea.search(self.no[i]) # 结果是list