0

I'd like to be able to ZIP all selected files/folders in one keyboard shortcut. How to enable this feature in Windows 7?

Currently these are the options:

  • Right-click > 7-Zip > Add to temp.zip

  • Right-click > Add to Temp.rar

  • *Right-click > Send to > Compressed (zipped) folder

enter image description here

Ideally, I'd like to have something like:

  • WIN+Z : zip selected files and automatically enter in renaming mode for the filename temp.zip (ready to be renamed)

  • WIN+SHIFT+Z: zip selected files with 7-zip and open the "Add to archive" dialog so that I can fill in a password.

What I've tried: Autohotkey with

#+z::
SendInput {AppsKey}7{Enter}
Return

I could do the same for #z with UP arrow, UP arrow, etc. but this is not very robust (sometimes the UI items change, etc.). Is there a better solution?

  • try using separate send commands for each keypress and put sleep 200 between them, it should be robust then – Mikhail V May 19 at 20:05
  • @MikhailV Yes but for some specific file types, some other options might be displayed in the menus (it's the case IIRC), so using a UP UP etc. is probably not ok for all file types. Is there a technique to do this without using simulated keypresses, but rather calling commands directly? – Basj May 19 at 20:38
  • without using context menu you mean? Yes I think, you can copy file paths to clipboard with alt+h then c then p. Then pass them to actual application (7-zip in your case). I would just use some more advanced file manager though ;) – Mikhail V May 19 at 21:14
0

Try

#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
}
| improve this answer | |
  • Not the answer you're looking for? – user3419297 May 27 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.