调用7zip解压函数

问题描述 投票:0回答:1

我想使用 7zip 上下文菜单的“在此处提取”功能。为此,我现在已经尝试了几件事。首先,我通过自动热键和按键笔划在上下文菜单中进行操作,但遗憾的是,这经常失败。之后我现在用批处理脚本尝试过。但这个批处理脚本总是在 AHK 目录中执行,而不是在标记的 .zip 所在的目录中执行。

它应该做什么:

基本上只需从上下文菜单 --> 7zip 菜单并单击/调用“在此处提取”即可。由于许多人已经在 AHK 脚本上留下了他们的牙齿(不执行该功能),我认为也许有一种方法可以批量工作?

实现该功能的最简单方法 --> 如果有一种方法可以直接通过注册表名称调用上下文菜单功能,例如我想要提取的 .zip 文件有时包含多个 zip 文件或仅包含文件夹和数据。

当前批次代码:

"C:\Program Files\7-Zip\7z.exe" e *.zip

通过 AHK 调用批次:

Run, "C:\Users\ThisPC\Desktop\test batch\batch.bat"

首先尝试在AHK中完全做到:

    XButton2::
Send, {AppsKey}
Sleep 75
Send, {Down}
Sleep 75
Send, ee
Sleep 75
Send, {Enter}
pageloaded := false
while(pageloaded = false)
{
    sleep 75
    ImageSearch, X, Y, 0, 0, A_ScreenWidth, A_ScreenHeight, Auto Rename.png
    if ErrorLevel = 0
    {
        pageloaded := true
    }
}
Send, {Right}{Right}{Enter}
try 
    {
    Run, "C:\Users\ThisPC\Desktop\Foldery\ProgramData\"
    }
catch e 
    {
    Run, "C:\Users\ThisPC\Desktop\Foldery\"
    }
return

编辑: 使用给出的第一个解决方案,它的工作原理如下: I selected the 1st.zip:

然后在选择 XButton2 时使用它来提取存档

这里不应该有文件夹,而是里面有目录敏感性的东西(比如将目录保留在里面,然后将它们放在“上方”,即第一个.zip 的当前目录中)

Sometimes, the 1st.zip consists of several .zips as they are only allowed to be 20 MB each, so all needs to be extracted: 在这种情况下, 1st.zip 包含 next1.zip ;下一个2.zip; next3.zip --> 所有这些都应该是 1:1,就像它们在 1st.zip 中一样,在 1st.zip 的同一文件夹中以 1:1 的方式提取。like this:

总体目录如下所示:

1st.zip |_ another1.zip |_ another2.zip |_ another3.zip
我希望解释得很好,如果您有疑问,请告诉我:)

batch-file autohotkey 7zip
1个回答
0
投票
尝试这个 AHK 脚本:

#NoEnv #SingleInstance Force #If WinActive("ahk_class CabinetWClass") || WinActive("Program Manager") ; Explorer or Desktop XButton2:: ; call 7zip extract here function Selection := Explorer_GetSelection() SplitPath, Selection, name, dir, ext, name_no_ext, drive If ext not in 7z,zip,rar return FileCreateDir, %dir%\%name_no_ext% SetWorkingDir %dir%\%name_no_ext% Run "C:\Program Files\7-Zip\7z.exe" x "%Selection%",,hide return #If ; 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 }
    
© www.soinside.com 2019 - 2024. All rights reserved.