I would like to know if there is a command in WinRar and 7zip that allows me to extract a compressed file into a new folder with the same file name, equivalent to right-clicking and selecting the <<extract in 'filename'/>> option. At the moment I only have the command in which you need to specify the folder in which the file will be extracted
Code: Select all
app := A_ProgramFiles "\WinRAR\WinRAR.exe"
destDir := "C:\Users\heseb\Downloads"
to := " "
; In WinRar:
RunWait % app " x """ fromArchiveFile """ *.* " to destDir ,, Hide
; In 7zip:
RunWait % app " x """ fromArchiveFile """ -o" to destDir,, Hide
Code: Select all
RunWait % app " e " "%1 """ fromArchiveFile """ -o" to "C:\temp\%1" " -r",, Hide
There should be 2 different commands, one for .rar and .zip files, since they are extracted with WinRaR and 7zip respectively
Complete script that extracts compressed files:
- getSelected() → Get the paths of selected files and folders both in Explorer and on the Desktop
- Detailed information of this script → viewtopic.php?f=76&t=121149
Code: Select all
#SingleInstance force
destDir := "C:\Users\heseb\Downloads"
;theseFiles7 := " " ; 7zip
theseFiles := " *.* " ; WinRAR
app7 := "C:\Program Files\7-Zip\7z.exe"
app := A_ProgramFiles "\WinRAR\WinRAR.exe"
extract := " x "
;irq := " %1 "
;to7 := " -o" ; 7zip
to := " " ; WinRAR
#If WinActive("ahk_exe explorer.exe")
!F2::
For each, fromArchiveFile in getSelected()
If (fromArchiveFile ~= "i)\.zip$")
RunWait % app " x """ fromArchiveFile """ -o" to destDir ,, Hide
;~ RunWait % app " e " "%1 """ fromArchiveFile """ -o" to "C:\temp\%1" " -r",, Hide
If (fromArchiveFile ~= "i)\.rar$")
RunWait % app " x """ fromArchiveFile """ *.* " to destDir ,, Hide
;~ MsgBox 64, Status, Done!
Return
#If
getSelected() { ; Get the paths of selected files and folders both in Explorer and on the Desktop
; https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256
; GEV: https://www.autohotkey.com/boards/viewtopic.php?p=514288#p514288
Static SWC_DESKTOP := 8, SWFO_NEEDDISPATCH := 1
WinGetClass winClass, % "ahk_id" hWnd := WinExist("A")
If !(winClass ~= "Progman|WorkerW|(Cabinet|Explore)WClass")
Return
shellWindows := ComObjCreate("Shell.Application").Windows, sel := []
If !(winClass ~= "Progman|WorkerW") {
For window in shellWindows
If (hWnd = window.HWND) && (shellFolderView := window.Document)
Break
} Else shellFolderView := shellWindows.FindWindowSW(0, 0, SWC_DESKTOP, 0, SWFO_NEEDDISPATCH).Document
For item in shellFolderView.SelectedItems
sel.Push(item.Path)
Return sel
}