[AHK]实现用TC打开并定位

Windows自带的资源管理器可以用命令行打开并定位某个文件夹,或文件。

TC也可以如下方式实现, “打开并定位” 某目录或某文件

#z::
tc:="E:\totalcmd\TOTALCMD.EXE"
;用文件测试 action_path:="G:\BaiduNetdickDownload\macOS High Sierra 10.13.iso"

;用目录测试
action_path:="G:\BaiduNetdickDownload\典范英语练习册和教学参考"
TC打开并定位(tc,action_path)
return


;作者:sunwind
;创作时间:2019年1月20日00:51:29
;最新更新时间:2020年11月23日17:03:13
;功能:用TC打开并定位某目录或某文件
;最新版本:https://blog.csdn.net/liuyukuan/article/details/86558810

TC打开并定位(tc,action_path)
{
  If InStr(FileExist(action_path), "D")  ;is Folder
  {
    run %tc% /O /T /A /S /L="%action_path%"
    if WinExist("ahk_class TTOTAL_CMD")
    {
      WinActivate
      send {backspace}
    }
  }else{
    run %tc% /O /T /A /S /L="%action_path%"
  }
}

 

 

以下是:用AutoHotkey+Everything.dll替代Listary实现在TC中定位文件

操作步骤:

双击Ctrl-->输入文件名-->调用Everything.dll快搜文件

-->选择搜索结果中某文件-->Shift+Eter 直接在TC中定位到该文件

 

/*
用AutoHotkey+Everything.dll替代Listary实现在TC中定位文件
操作步骤:

双击Ctrl-->输入文件名-->调用Everything.dll快搜文件
-->选择搜索结果中某文件-->Shift+Eter 直接在TC中定位到该文件
 
*/
;作者:sunwind
;创作时间:2019年1月20日00:51:29
;最新更新时间:2019年3月27日
;功能:用ahkAHK版Listary
;最新版本:https://blog.csdn.net/liuyukuan/article/details/86558810

;-------------------------------------------
;准备工作:
; 1、未安装Everything的先去官网 www.voidtools.com 下载并安装Everything。
; 2、下载SDK压缩包(https://www.voidtools.com/Everything-SDK.zip),并将包中的Dll文件解压到本 脚本所在的目录。
; 3、运行 Everything.exe 不要退出,让它建立全盘的数据库
;4、使用前先在脚本里配置TotalCommander路径
;-------------------------------------------
;用法:
;1、双击Ctrl呼叫出搜索框
;2、输入要搜内容后回车
;3、弹出搜索结果列表
;4、用数字键或↑↓键选择(也可以用鼠标选定)某条结果
;5、按Shift+Enter(也可以用鼠标双击),调用TotalCommander定位该文件
;6、增加显示修改日期,并按日期降序排列
 
 
#SingleInstance,force
tc:="E:\totalcmd\TOTALCMD.EXE"
Gui, Add, ListView, r20 w700 gMyListView AltSubmit, 序号|路径|修改时间

IfNotExist,%A_ScriptDir%\Everything32.dll
	{
		MsgBox,17,,没有找到Everything32.dll,将不能运行`n需要下载 https://www.voidtools.com/Everything-SDK.zip,`n并将Everything32.dll放到【%A_ScriptDir%】目录下`n是否需要从网上下载?
		IfMsgBox Ok
		{
			;感谢hui-Zz的github
			URLDownloadToFile,https://www.voidtools.com/Everything-SDK.zip,Everything-SDK.zip
			Sleep,1000
			TrayTip, 请手动处理, 将包中的Dll文件夹里的Everything32.dll 文件解压到%A_ScriptDir%!
			RunWait,Everything-SDK.zip
			Reload
		}
		else
		{
			TrayTip, 无法运行, 请手动将Everything32.dll放到脚本目录后 再运行!
			ExitApp
		}
	}

TrayTip, 已就绪, 双击Ctrl试试吧!
SetTimer, HideTrayTip, -5000
return
 
MyListView:
if A_GuiEvent = DoubleClick
{
    LV_GetText(action_path, A_EventInfo,2)  
	run %tc% /O /T /A /S /L="%action_path%"
	Gui,Cancel
}
return
 
#IfWinActive,AHK版Listary
+Enter::
RowNumber = 0  ; 这样使得首次循环从列表的顶部开始搜索.
Loop
{
    RowNumber := LV_GetNext(RowNumber)  ; 在前一次找到的位置后继续搜索.
    if not RowNumber  ; 上面返回零, 所以选择的行已经都找到了.
        break
    LV_GetText(action_path, RowNumber,2)
	run %tc% /O /T /A /S /L="%action_path%"
	Gui,Cancel
}
return
^o::
RowNumber = 0  ; 这样使得首次循环从列表的顶部开始搜索.
Loop
{
    RowNumber := LV_GetNext(RowNumber)  ; 在前一次找到的位置后继续搜索.
    if not RowNumber  ; 上面返回零, 所以选择的行已经都找到了.
        break
    LV_GetText(action_path, RowNumber,2)
	;~ MsgBox % "这里可以设置对话框切换功能,切到" action_path
	
	Gui,Cancel
	ChangePath(action_path)
}
#IfWinActive
 
 
~LCtrl::
Keywait, LCtrl, , t0.5
if errorlevel = 1
	return
else
	Keywait, LCtrl, d, t0.1
if errorlevel = 0
{
	main()	
}
 
return

^F1::
main()
{	
	InputBox, UserInput, 请输入你要定位的内容:, , , 320, 120

	if  ErrorLevel
	{
		return
	}
	else
	{
		if strlen(UserInput)=0
			return
		else
		{
			obj := {} 
			obj:=搜索(UserInput)
		}
		;得到搜索结果
	}
	
	Gui, Show,, AHK版Listary
	LV_Delete()
	
	theLen:=obj.Count()
	loop,%theLen%
	{
		LV_Add("",A_Index,obj.GetFullPath(A_Index-1),obj.GetResultDateModified(A_Index-1))
	}
	;~ LV_ModifyCol(2,"Auto")  ; 自动调整列宽.
	LV_ModifyCol(2,500)  ; 自动调整列宽.
}
 
搜索(keyword)
{
	Obj:=new Everything(A_ScriptDir)
	Obj.Setkey(keyword)
	Obj.SetRequestFlags()	;搜索哪些字段
	Obj.SetSort()	;按哪个字段排序
	Obj.Search()	;执行搜索动作
	return Obj
}
 
 
;~ 在心如止水写的Everything类增加了获得文件创建、修改时间功能:
;~ https://github.com/Oilj/BeanLib/blob/master/Everything.ahk

class Everything{
 
key:="",MatchWholeWord:=false,dll:=false
;---------------------------------------------------------------------- 
;获取Everthingdll
;预先明确装载
getdll(dllPath:=""){

	if(dllPath="")
	{
		dllPath:=A_ScriptDir
		outputdebug "【dllPath为空被赋值】" %A_ScriptDir%
	}
	dll:=false


	;~ dll:=A_PtrSize=8 ? "Everything64.dll" : "Everything32.dll"
	
	if(FileExist(dllPath "\Everything32.dll")){
		outputdebug "【dllPath】存在Everything32.dll"
		dll:=DllCall("LoadLibrary", str,dllPath . "\Everything32.dll") ? "Everything32.dll" : "Everything64.dll"
		outputdebug ★ErrorLevel  %ErrorLevel%
		outputdebug "【dll】" %dll%
	}
	else if(FileExist(dllPath "\Everything64.dll")){
		outputdebug "【dllPath】存在Everything64.dll"
		dll:=DllCall("LoadLibrary", str,dllPath .  "Everything64.dll") ? "Everything64.dll" : "Everything.dll"
		outputdebug ErrorLevel  %ErrorLevel%
		outputdebug "【dll】" %dll%
	}
	if Not(dll){
		throw Exception(" Everything.dll is not Exist.")
	}
	outputdebug "-------$getdll--------"
	return dll
}
 
;---------------------------------------------------------------------- 
 
 
 
__New(dllPath:=""){
	
	;~ if Not(WinExist("ahk_exe Everything.exe")){
	;~ throw Exception("ahk_exe Everything.exe is not Exist.")
	;~ }
	
	dll:=this.getdll(dllPath)
	outputdebug "----->dll" %dll%
	if Not(dll){
    outputdebug "没得到dll-》" %dll%
    throw Exception("Not Found Everthing.dll/Everthing64.dll.")
	}
	
	this.dll:=dll
	outputdebug "this.dll-》" %dll%
	this.hModule := DllCall("LoadLibrary", str, this.dll)
 
	return this
}
 
__Delete(){
	DllCall("FreeLibrary", "UInt", this.hModule)
	return
}
 
;设置关键词
SetKey(aValue){
	this.key := aValue
	DllCall(this.dll "\Everything_SetSearch",str,this.key)
	return
}
 
;设置全字匹配
SetMatchWholeWord(aValue){
	this.MatchWholeWord := aValue
	DllCall(this.dll "\Everything_SetMatchWholeWord",int,aValue)
	return
}

; 设置搜索需要返回哪些结果的选项
SetRequestFlags(){
	DllCall(this.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) )
	return
}
 
SetSort()
{
	; 文件路径升序排序:EVERYTHING_SORT_PATH_ASCENDING:=3
	; 创建时间升序排序:EVERYTHING_SORT_DATE_CREATED_ASCENDING:=11
	; 修改时间降序排序:EVERYTHING_SORT_DATE_MODIFIED_DESCENDING:=14
	DllCall(this.dll  "\Everything_SetSort", "int",14)
}
 
;执行搜索动作 (执行后直接返回匹配数)
Search(aValue=1){
	DllCall(this.dll "\Everything_Query",int,aValue)
	return
}
 
;返回匹配总数
Count(){
	return DllCall(this.dll "\Everything_GetTotResults")
}
 
;返回文件名
GetFileName(aValue){
	return StrGet(DllCall(this.dll "\Everything_GetResultFileName",int,aValue))
}
 
;返回文件全路径
GetFullPath(aValue,cValue=128){
	VarSetCapacity(bValue,cValue*2)
	DllCall(this.dll "\Everything_GetResultFullPathName",int,aValue,str,bValue,int,cValue)
	return bValue
}
GetTime(ByRef date) {
  static add_hours
  if !add_hours
  {
    add_hours:=A_Now
    add_hours-=A_NowUTC, Hours	;得到时区差
	;~ Coordinated Universal Time(UTC):又称为世界标准时间;
	;~ 比如,中国内地的时间与UTC的时差为+8,也就是UTC+8。 
	;~ Calendar Time:日历时间,是用“从一个标准时间点到此时的时间经过的秒数”来表示的时间。日历时间对于不同的编译器,是不同的。
	;~ 但是无论你在哪一个时区,在同一时刻对同一个标准时间点来说,日历时间都是一样的。
	;~ 例如,time_t就是一种日历时间,其值表示从UTC(Coordinated Universal Time)时间1970年1月1日00:00:00(称为UNIX系统的Epoch时间) 到当前时刻的秒数。
	;~ FILETIME表示自UTC(Coordinated Universal Time)时间1601年1月1日开始的100纳秒为单位的时间
	;~ 注释:公元1601年到公元1970年相差369年,转化为秒数即为11644473600秒。
	;~ 日历时间到FILETIME  公式:  ld=(日历时间转成time_t+11644473600秒)*10000000
	;~ FILETIME.dwLowDateTime=ld
	;~ hd=ld>>32
	;~ FILETIME.dwHighDateTime=hd
  }
  /*
  入参date是
  FILETIME结构持有的64位无符号的文件的日期和时间值。此值表示自UTC(Coordinated Universal Time)时间1601年1月1日开始的100纳秒为单位的时间。
	dwLowDateTime 低位32位的文件的时间值。
	dwHighDateTime 高位32位的文件的时间值。
FILETIME的定义是这样的
typedef struct  _FILETIME
    {
    DWORD dwLowDateTime;
    DWORD dwHighDateTime;
    } FILETIME;
FILETIME这个名字很奇怪,其实他跟FILE并没有直接关系,只是很多File的API中,都以这个为时间的类型,比如你可以调用GetFileTime来取得File的创建/修改/访问时间。
FILETIME是一个__int64
1ms (毫秒)	1毫秒=0.001秒=10-3秒(millisecond)
1μs (微秒)	1微秒=0.000001=10-6秒(microsecond)
1ns (纳秒)	1纳秒=0.000000001秒=10-9秒(nanosecond)
1ps (皮秒)	1皮秒=0.000000000001秒=10-12秒
1fs (飞秒)	1飞秒=0.00000000000001秒=10-15秒

时间格式:DosDateTime <====>FileTime <====> SystemTime

                    |               |               |

使用上面          LocalFileTime  FileName   系统时间和本地时间

格式的时间:      (本地时区)    (UTC)        

                
  */
  ;FILETIME To Time_t
  ;FILETIME单位是100纳秒  Time_t单位是秒,差10^7次方
  ;~ 对于结构体首个成员变量的偏移总为 0. 第二个成员的偏移为 0 加上首个成员的大小(一般为 4 字节). 
  HighPart:=NumGet(date,4,"uint")<<32
  LowPar:=NumGet(date,0,"uint")
  ;~ sec1:=(NumGet(date,4,"uint")<<32|NumGet(date,0,"uint"))// 10000000
  sec:=(HighPart+LowPar)//10000000
  
 
  t:="16010101"
  t+=sec, Seconds
  t+=add_hours, Hours
  return, t
}
 
 ;返回文件创建时间
GetResultDateCreated(i){
	VarsetCapacity(date1, 8, 0)
	DllCall(this.dll "\Everything_GetResultDateCreated", "int",i, "Ptr",&date1)
	return this.GetTime(date1)
}


 ;返回文件修改时间
GetResultDateModified(i){
	VarsetCapacity(date2, 8, 0)
	DllCall(this.dll "\Everything_GetResultDateModified", "int",i, "Ptr",&date2)
	return this.GetTime(date2)
}

 
}
 
HideTrayTip() {  ; NOTE: For Windows 10, replace this function with the one defined above.
    TrayTip
}

ChangePath(LongPath)
{
    If InStr(FileExist(LongPath), "D")  ;is Folder
      dir:=LongPath
    else
      SplitPath,LongPath,filename,dir,ext,nameNoExt,drv
     
    ;~ ControlGetText, w_Edit1Text, Edit1, A
    ;~ ControlClick, Edit1, A
    ControlSetText, Edit1, %dir%, A
    ControlSend, Edit1, {Enter}, A
    ;~ Sleep,100
    ;~ ControlSetText, Edit1, %w_Edit1Text%, A
	return dir
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

liuyukuan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值