Extract compressed file Topic is solved
Extract compressed file
I have WinRar installed and I would like to know if the program has command line functions to extract the compressed files using a hotkey with autohotkey. I haven't found this, so I've seen other alternatives for this, like:
https://www.autohotkey.com/board/topic/23219-extract-from-rar-075-090/
https://www.autohotkey.com/board/topic/86876-unrarhk-unrar-your-moviesseries-efortlessly-from-context-menu/
This only accepts .rar files:
viewtopic.php?t=55680
Thank you in advance
https://www.autohotkey.com/board/topic/23219-extract-from-rar-075-090/
https://www.autohotkey.com/board/topic/86876-unrarhk-unrar-your-moviesseries-efortlessly-from-context-menu/
This only accepts .rar files:
viewtopic.php?t=55680
Thank you in advance
Last edited by Elermino on 10 Sep 2023, 16:27, edited 1 time in total.
Re: Extract compressed file
WinRAR -> Help -> Help topics -> Command line mode -> Command line syntax
You can then use the Run command with your command line.
You can then use the Run command with your command line.
Re: Extract compressed file
Thanks for your reply. How do I get it to detect if a file is selected in the file explorer or the desktop and extract it?
Maybe this is the correct syntax for the Run command?
Code: Select all
run, unrar e %FilePath%
Re: Extract compressed file
If you search forum for "ExplorerGetSelection", you should see the function by teadrinker that will do that part.
An adapted one: viewtopic.php?p=514288#p514288
An adapted one: viewtopic.php?p=514288#p514288
Code: Select all
#Requires AutoHotkey v1.1.33
dir := A_ScriptDir
fromRARfile := dir "\temp2.rar"
toDestDir := dir "\t"
theseFiles := "*.*"
; -------------------------------------------------------------------------
app := A_ProgramFiles "\WinRAR\WinRAR.exe"
extract := "x"
_ := " "
RunWait % app _ extract _ fromRARfile _ theseFiles _ toDestDir "\",, Hide
MsgBox 64, Status, Done!
Re: Extract compressed file
Sorry, how can I get this script to work so that it detects the selected file and extracts it to a single folder?mikeyww wrote: ↑05 Sep 2023, 11:30If you search forum for "ExplorerGetSelection", you should see the function by teadrinker that will do that part.
An adapted one: viewtopic.php?p=514288#p514288
Code: Select all
#Requires AutoHotkey v1.1.33 dir := A_ScriptDir fromRARfile := dir "\temp2.rar" ...
I tried this but no result
Code: Select all
~!x::
;~ send, ^+x
file := getSelected()
dir := A_ScriptDir
fromRARfile := dir "\" file
toDestDir := dir "\t"
theseFiles := "*.*"
; -------------------------------------------------------------------------
app := A_ProgramFiles "\WinRAR\WinRAR.exe"
extract := "x"
_ := " "
RunWait % app _ extract _ fromRARfile _ theseFiles _ toDestDir "\",, Hide
MsgBox 64, Status, Done!
getSelected(){
; https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256
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 := 8, 0, SWFO_NEEDDISPATCH := 1).Document
For item in shellFolderView.SelectedItems
sel.Push(item.Path)
Return sel
}
Re: Extract compressed file
That function on
viewtopic.php?p=514288#p514288
didn't always work.
I replaced it by this one:
viewtopic.php?p=514288#p514288
didn't always work.
I replaced it by this one:
Code: Select all
; Get path of selected files/folders:
getSelected(){
; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=60403&p=255273#p255256
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
}
Re: Extract compressed file
If your paths contain spaces, you might need to add some quotation marks to your command line.
Code: Select all
#Requires AutoHotkey v1.1.33
toDestDir := A_ScriptDir "\t"
theseFiles := "*.*"
app := A_ProgramFiles "\WinRAR\WinRAR.exe"
extract := "x"
_ := " "
#If WinActive("ahk_class CabinetWClass")
!x::
For each, fromRARfile in getSelected()
If (fromRARfile ~= "i)\.rar$")
RunWait % app _ extract _ fromRARfile _ theseFiles _ toDestDir "\",, 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
}
Re: Extract compressed file
Unfortunately it doesn't work here:mikeyww wrote: ↑06 Sep 2023, 09:23Code: Select all
getSelected() { ; Get the paths of selected files and folders both in Explorer and on the Desktop ... Return sel }
Code: Select all
F1:: MsgBox, % getSelected()
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
}
Re: Extract compressed file
An array is returned, so try the enumerating script that I posted.
Re: Extract compressed file
Ok, thanks. It works for that case.
Code: Select all
#If WinActive("ahk_class CabinetWClass") || WinActive("Program Manager")
F1::
For each, TXTfile in getSelected()
If (TXTfile ~= "i)\.txt$")
RunWait % TXTfile
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
try 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
try sel.Push(item.Path)
Return sel
}
Code: Select all
F1:: MsgBox, % getSelected()
Code: Select all
clipboard := getSelected()
I mean, to avoid confusion it should have another name.
Re: Extract compressed file
You can use SplitPath for any item. Will be the same for all of them.
Re: Extract compressed file
Yes, I recommend that you post the revised script that you are currently using.
Re: Extract compressed file
Is this:
Code: Select all
toDestDir := A_ScriptDir
theseFiles := "*.*"
app := A_ProgramFiles "\WinRAR\WinRAR.exe"
extract := "x"
_ := " "
#If WinActive("ahk_class CabinetWClass")
!F2::
For each, fromRARfile in getSelected()
If (fromRARfile ~= "i)\.rar$")
RunWait % app _ extract _ fromRARfile _ theseFiles _ toDestDir "\",, 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
}
Re: Extract compressed file
Below is an update for Zip. Use a registered copy of WinRAR. 7zip is a free alternative if you just want to unpack.
Code: Select all
#Requires AutoHotkey v1.1.33
destDir := A_ScriptDir "\t\"
theseFiles := " " ; 7zip
theseFiles := " *.*" ; WinRAR
app := "d:\utils\7zip\x64\7za.exe"
app := A_ProgramFiles "\WinRAR\WinRAR.exe"
extract := " x "
to := "-o" ; 7zip
to := " " ; WinRAR
#If WinActive("ahk_class CabinetWClass")
!x::
For each, fromArchiveFile in getSelected()
If (fromArchiveFile ~= "i)\.(rar|zip)$")
RunWait % app extract fromArchiveFile theseFiles 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
}
Re: Extract compressed file
Amazing script, thank you sirmikeyww wrote: ↑06 Sep 2023, 20:23Below is an update for Zip. Use a registered copy of WinRAR. 7zip is a free alternative if you just want to unpack.
Code: Select all
#Requires AutoHotkey v1.1.33 destDir := A_ScriptDir "\t\" theseFiles := " " ; 7zip theseFiles := " *.*" ; WinRAR app := "d:\utils\7zip\x64\7za.exe" app := A_ProgramFiles "\WinRAR\WinRAR.exe" extract := " x " to := "-o" ; 7zip to := " " ; WinRAR #If WinActive("ahk_class CabinetWClass") !x:: For each, fromArchiveFile in getSelected() If (fromArchiveFile ~= "i)\.(rar|zip)$") RunWait % app extract fromArchiveFile theseFiles to destDir,, Hide MsgBox 64, Status, Done! Return #If ... }
Re: Extract compressed file
Hello. Sorry for opening this topic again, but I have not been able to get the .zip files to be extracted, since I already installed 7zip and set the directory to '7z.exe'. I changed a bit of your code but there are no results, with the original code I get a box saying 'No files found'. I ask for one last help to solve this problem please.mikeyww wrote: ↑06 Sep 2023, 20:23Below is an update for Zip. Use a registered copy of WinRAR. 7zip is a free alternative if you just want to unpack.
Code: Select all
#Requires AutoHotkey v1.1.33 destDir := A_ScriptDir "\t\" theseFiles := " " ; 7zip theseFiles := " *.*" ; WinRAR app := "d:\utils\7zip\x64\7za.exe" app := A_ProgramFiles "\WinRAR\WinRAR.exe" extract := " x " to := "-o" ; 7zip to := " " ; WinRAR #If WinActive("ahk_class CabinetWClass") !x:: For each, fromArchiveFile in getSelected() ... }
Thank you!
My attempt:
Code: Select all
destDir := A_ScriptDir
theseFiles7 := " " ; 7zip
theseFiles := " *.*" ; WinRAR
app7 := "C:\Program Files\7-Zip\7z.exe"
app := A_ProgramFiles "\WinRAR\WinRAR.exe"
extract := " x "
to7 := "-o" ; 7zip
to := " " ; WinRAR
#If WinActive("ahk_class CabinetWClass")
!x::
For each, fromArchiveFile in getSelected()
If (fromArchiveFile ~= "i)\.rar$") ; Change this to fist case rar else if zip
RunWait % app extract fromArchiveFile theseFiles to destDir,, Hide
else if (fromArchiveFile ~= "i)\.zip$")
RunWait % app7 extract fromArchiveFile theseFiles7 to7 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
}
Re: Extract compressed file
If you change RunWait to MsgBox, I think you will find that a space is missing in your command line.
Re: Extract compressed file
Are you running the script that you posted? Does not look right or match what I see. Zip files should be using 7z, according to your script.
This worked for me when my path had spaces.
Perhaps the variables complicate too much. Can simplify:
This worked for me when my path had spaces.
Code: Select all
RunWait % app7 extract """" fromArchiveFile """" theseFiles7 to7 destDir,, Hide
Code: Select all
RunWait % app7 " x """ fromArchiveFile """ -o" destDir,, Hide