-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheverything_api.py
More file actions
28 lines (21 loc) · 856 Bytes
/
everything_api.py
File metadata and controls
28 lines (21 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import ctypes, os
from pathlib import Path
# Load the Everything DLL
everything_dll = ctypes.WinDLL(os.path.abspath(Path('Everything64.dll')))
def search(query: str) -> list:
directory = Path.home()
# Prepend the directory and a wildcard to the search query
query = f"{directory}\\*{query}*"
# Set the search query
everything_dll.Everything_SetSearchW(query)
# Execute the query
everything_dll.Everything_QueryW(True)
# Get the number of results
num_results = everything_dll.Everything_GetNumResults()
results = []
for i in range(num_results):
# Get the result's full path and file name
result = ctypes.create_unicode_buffer(260) # MAX_PATH = 260
everything_dll.Everything_GetResultFullPathNameW(i, result, len(result))
results.append(result.value)
return results