Hayashikawa

Hayashikawa

7-Zip uses AutoHotkey for quick decompression of compressed files.

Preface#

I have been using Bandizip and really like its "Auto Extract" feature, which is different from the "Extract to Folder" feature.

Official Description

  • When there is only one file in the compressed package, it will be extracted to the "current folder".

  • When all the files in the compressed package are in the same folder, they will be extracted to the "current folder".

  • Otherwise, they will be extracted to the "file name folder".

Files compressed in Unix are usually bundled in a folder. When extracting these files to the "file name folder", multiple folders with the same name will appear, which is inconvenient.

In this case, the "Auto Extract" feature is very convenient. Bandizip will automatically determine whether to extract the files to the "current folder" or the "file name folder".

Today, I suddenly uninstalled Bandizip and installed the well-known 7-Zip. I found that it is cumbersome to use the "Extract to Folder" option in the right-click menu on Windows 11. Since 7-Zip does not adapt to the new version of the right-click menu on Windows 11, I have to go through multiple levels of menus to find it, and it only offers the clumsy option of "Extract to Folder". If I directly open the compressed package and use the "Extract" option in the toolbar, it will extract the files directly to the directory where the compressed package is located, which is messy.

So I started searching for a shortcut. First, I found Nanazip, which adapts to the new version of the right-click menu on Windows 11, but I don't like secondary development unless necessary. Then I found a method using AutoHotkey to implement the "Ctrl + Alt + Left Click" to select the compressed package and extract it. I tried to reproduce the script I found online but failed, so I made some simple modifications to the script and tried again, but still failed.

Finally, I chose to compromise and still use AutoHotkey, but with a different approach.

Approach#

  1. Select the compressed file.

  2. Use AutoHotkey to send the "Ctrl + C" command to copy the file path of the compressed file to the clipboard.

    When copying files in Windows, only the file path is stored in the clipboard, with the type CF_HDROP representing a file list. The files are actually copied when pasted.

    CF_HDROP: A handle of type HDROP used to identify a file list. An application can retrieve information about the files by passing the handle to the DragQueryFile function.

  3. Read the compressed file path from the clipboard and assign it to the variable SelectedFile.

  4. Remove the extension and everything after the last dot from the variable SelectedFile, and assign it to the variable dirAndFileName.

  5. Run the command `7z x "%SelectedFile%" -o"%dirAndFileName%" -y" to call 7-Zip to extract the compressed file.

Script Content#

!x::
  ; Copy the selected file
  SendInput, ^c
  Sleep 50
  ; Read the selected file path from the clipboard
  SelectedFile := Clipboard
  ; Create a variable for the folder with the same name as the file
  dirAndFileName := SubStr(SelectedFile, 1, InStr(SelectedFile, ".", 0, -1) - 1)
  ; Extract to the folder with the same name as the file
  RunWait, 7z x "%SelectedFile%" -o"%dirAndFileName%" -y
return

Usage#

Save the script content as an AutoHotkey file and run it. Select the compressed file and use the shortcut key Alt + X to directly extract the compressed file.

Conclusion#

However, it is still not as convenient as Bandizip's "Auto Extract" feature (XD). As long as it works, don't uninstall it randomly.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.