我希望能够通过一个键盘快捷键压缩所有选定的文件/文件夹。如何在 Windows 7 中启用此功能?
目前有以下选项:
右键单击 > 7-Zip > 添加到 temp.zip
右击 > 添加到 Temp.rar
*右键单击 > 发送到 > 压缩文件夹
理想情况下,我想要的是类似这样的内容:
WIN+ Z:压缩选定的文件并自动进入文件名重命名模式
temp.zip
(准备重命名)WIN++ SHIFT:Z使用 7-zip 压缩选定的文件,然后打开“添加到存档”对话框,以便我可以填充在密码中。
我尝试过的:使用 Autohotkey
#+z::
SendInput {AppsKey}7{Enter}
Return
我可以用向上箭头、向上箭头等做同样的事情#z
,但这不是很可靠(有时 UI 项目会发生变化等)。有没有更好的解决方案?
答案1
尝试
#IfWinActive ahk_class CabinetWClass ; explorer
#z::
explorer_path := "" ; empty this variable
selection := ""
filename := ""
InputBox, filename, Enter a name for the archive, ,,300
if ErrorLevel
return
explorer_path := GetActiveExplorerPath()
selection := Explorer_GetSelection()
ToolTip, Wait for `n%explorer_path%\%filename%.zip"
Loop, parse, selection, `n
RunWait, %comspec% /c "7z.exe a "%explorer_path%\%filename%.zip" "%A_LoopField%"",,hide UseErrorLevel ; if it doesn't work replace 7z.exe with its path.
Process, WaitClose, 7z.exe
ToolTip
return
#IfWinActive
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=69925
GetActiveExplorerPath()
{
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==explorerHwnd)
{
return window.Document.Folder.Self.Path
}
}
}
}
; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=60403&p=255273#p255256
Explorer_GetSelection(){
WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A") ; %
if !(winClass ~="Progman|WorkerW|(Cabinet|Explore)WClass")
Return
shellWindows := ComObjCreate("Shell.Application").Windows
if (winClass ~= "Progman|WorkerW")
shellFolderView := shellWindows.FindWindowSW(0, 0, SWC_DESKTOP := 8, 0, SWFO_NEEDDISPATCH := 1).Document
else {
for window in shellWindows
try if (hWnd = window.HWND) && (shellFolderView := window.Document)
break
}
for item in shellFolderView.SelectedItems
result .= (result = "" ? "" : "`n") . item.Path
if !result
result := shellFolderView.Folder.Self.Path
Return result
}