I noticed that there are people trying to come up with a way to extract .tar.gz files in one go on Windows. For instance, I was reading: How can I unzip a .tar.gz in one step (using 7-Zip)? While on a unix system this is trivial, with 7-zip on Windows this becomes a two-step process. There are of course a lot of solutions to this on Windows. The way I prefer to do it on Windows 7, is to have a context menu on Windows Explorer, right-click and extract the file in one go.

You can download the Registry file I created right here: 7zip-extract-tar-gz.reg, use Save Link As to save it as a file, then double-click to import it into your registry: at your own risk of course!
You will also need to have the 7zip executables in your environment PATH for this to work.

To do this first create the context menu entry:

  • open the Registry Editor (regedit.exe)
  • go to HKEY_CURRENT_USER\Software\Classes
  • create a new key called 7-zip.gz
  • under 7-zip.gz create another key called shell
  • under shell create another key called any name you like, e.g. extract_tar_gz
  • provide a value for that last key, which is the text that will appear in the context menu of Windows Explorer when you right-click a .gz file. I named mine Extract .tar.gz
  • create another key this time called command
  • the value of this key must be (put all text in one line!!):
    cmd /c @for %%f in ("%1") do ( 
         @7z x -y "%%~ff" -o"%%~dpf" &&  
         @for %%i in ("%%~nf") do ( 
              @if %%~xi==.tar ( 
                   @7z x -y "%%~fi" -o"%%~dpi" && del "%%~fi"
              )
         ) 
    ) 
    && pause
    

the 7-zip.gz registry key hierarchy should now look like this:

Registry key hierarchy for the context menu to extract .tar.gz files

Registry key hierarchy for the context menu to extract .tar.gz files

It is assumed that the command line utility of 7-zip (7z.exe) is available in your PATH. If it isn’t add it.
Of course instead of squeezing the commands of extracting the files one after the other and then deleting the intermediate .tar file, you could write a more elaborate batch file and invoke that to handle the situation and add some error checking too. You could potentially do a similar process for .tar.bz2 files.

To use it open a Windows Explorer and locate your .tar.gz file, right-click and select the command you added. Mine looks like this:

Context menu that appears on Windows Explorer.

Keep in mind that this command will not clutter your context menu, as it will only appear when you right-click a .gz file. Also note that the script does some basic checking if the .gz file does have a .tar in it, but don’t expect it to be of commercial software quality, it’s just a quick hack!

The command looks cryptic, but the logic is actually extremely simple. Do you want the command explained?


Changelog:

23/07/2014 – Created a .reg file that can be imported into the Windows 7 Registry (use with caution on other OSes)
28/12/2013 – Fixed problem with archives that contained spaces. (thanks to Orinoco for reporting it)

0