Monday, November 10, 2008

Using 7zip to extract .tar.gz / .tar.bz2 / .tgz / .tbz files in a single step

I love 7zip. It's really great. It saves huge amounts of time with its great Explorer shell integration and lack of nag screens. I can right-click a file, or a bunch of files, and have them all extracted to the current directory, or have directories created for each based on their name...as well as a bunch of other intuitive and time-saving functions.

However, one thing it sorely lacks is the ability to extract compressed tarballs (.tar.gz, .tar.bz2, .tgz, etc) in a single step. Instead, it merely uncompresses the file, leaving you with an uncompressed tarball; then you have to right-click THAT file and have 7zip extract it.

WinRAR does it right, but isn't open source or even properly free in any way. It's shareware, complete with nag screens. It also doesn't do everything 7zip does.

So, I decided to kludge it up the old-fashioned way. Here's how:

1. Create a batch file named c:\windows\system32\untgz.cmd. Put the following commands in it:
C:\"Program Files"\7-Zip\7z x -so %* > untgztemp.tar
C:\"Program Files"\7-Zip\7z x untgztemp.tar
del untgztemp.tar


2. Save the following into a .reg file and run it to import the settings to your registry.
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\Shell\UnTarGz]
@="Extract from compressed TAR"

[HKEY_CLASSES_ROOT\*\Shell\UnTarGz\command]
@="\"c:\\windows\\system32\\untgz.cmd\" \"%1\""


3. Now, when you right-click ANY file type, you will get an option that says "Extract from compressed TAR". Clicking that option will run the file through the commands in that batch file.

If you don't understand the batch file commands in step 1, then YOU SHOULD NOT USE THIS KLUDGE. This is a tool for people who understand to be lazy, not a tool to make it easy for average users; it does not contain any of the protections necessary to avoid DESTROYING YOUR DATA.