; 【AHK调用Everything接口的例子】  By FeiYue

/*
准备工作:
1、先去 www.voidtools.com 下载安装Everything,并下载SDK压缩包

2、将SDK压缩包中的Dll文件解压到 AutoHotkey.exe 程序所在的目录

3、运行 Everything.exe 不要退出,让它建立全盘的数据库
*/

FindStr:="file: AutoHotkey"
dll:=A_PtrSize=8 ? "Everything64.dll" : "Everything32.dll"
dll:=RegExReplace(A_AhkPath, "[^\\]+$", dll)
hModule:=DllCall("LoadLibrary", "Str",dll, "Ptr"), dll.="\"
DllCall(dll "Everything_SetSearch", "Str",FindStr)
; 设置搜索需要返回哪些结果的选项
DllCall(dll "Everything_SetRequestFlags", "int"
  , (EVERYTHING_REQUEST_FILE_NAME:=0x00000001)
  | (EVERYTHING_REQUEST_PATH:=0x00000002)
  | (EVERYTHING_REQUEST_SIZE:=0x00000010)
  | (EVERYTHING_REQUEST_DATE_CREATED:=0x00000020)
  | (EVERYTHING_REQUEST_DATE_MODIFIED:=0x00000040) )
; 文件路径升序排序:EVERYTHING_SORT_PATH_ASCENDING:=3
; 创建时间升序排序:EVERYTHING_SORT_DATE_CREATED_ASCENDING:=11
; 修改时间降序排序:EVERYTHING_SORT_DATE_MODIFIED_DESCENDING:=14
DllCall(dll "Everything_SetSort", "int",3)
DllCall(dll "Everything_Query", "int",1)
num:=DllCall(dll "Everything_GetNumResults"), s:=""
; msgbox, % "错误值:" DllCall(dll "Everything_GetLastError")
VarsetCapacity(fullname, 255*2, 0)
VarsetCapacity(date1, 8, 0)
VarsetCapacity(date2, 8, 0)
Loop, % (num>5 ? 5:num)
{
  i:=A_Index-1
  ; 两种方式获取文件的完整路径,推荐后面那种
  path:=DllCall(dll "Everything_GetResultPath", "int",i, "Str")
  name:=DllCall(dll "Everything_GetResultFileName", "int",i, "Str")
  DllCall(dll "Everything_GetResultFullPathName", "int",i, "Str",fullname, "int",255)
  ; 获取文件大小和创建、修改时间
  DllCall(dll "Everything_GetResultSize", "int",i, "int64*",size)
  DllCall(dll "Everything_GetResultDateCreated", "int",i, "Ptr",&date1)
  DllCall(dll "Everything_GetResultDateModified", "int",i, "Ptr",&date2)
  s.=path "\" name "`n" fullname
    . "`n文件大小: " Round(size/1024) "Kb"
    . "`n创建时间: " GetTime(date1)
    . "`n修改时间: " GetTime(date2) "`n`n"
}
DllCall("FreeLibrary", "Ptr",hModule)
MsgBox, 4096,, %s%
return
GetTime(ByRef date) {
  static add_hours
  if !add_hours
  {
    add_hours:=A_Now
    add_hours-=A_NowUTC, Hours
  }
  sec:=(NumGet(date,4,"uint")<<32|NumGet(date,0,"uint"))//10000000
  t:="16010101"
  t+=sec, Seconds
  t+=add_hours, Hours
  return, t
}

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。