I'm trying to find a way to make the action you can perform from the context menu, "Extract to <folder_same_as_file_name>" the default action when double-clicking the file instead of simply launching 7-zip. Is there a simple way to do this?

In the alternative, I gather I could try passing parameters into the following:

7z x <filename> -o<filename>

But I'm not sure how to set this up (how to pass the filename parameter, and can I do this directly or will I have to write a batch file instead and pass the filename to it? The latter I find irritatingly unelegant, but whatever works.

link|improve this question
feedback

3 Answers

up vote 0 down vote accepted

afrazier:

unfortunately your batch program method won't work; windows doesn't handle opening multiple files like that. when you try to open multiple files with a program, windows doesn't open a single instance of the program and pass the files as multiple arguments to that one instance. instead, windows opens many instances of the program (as many instances as there are files), passing one file to each instance. it would be nice if you could just use %* and pass a bunch of files to a single .bat, and have that .bat run a loop processing each file one at a time, but unfortunately you can only use %1 when setting these kinds of actions in the registry. freaking windows!!

someone with some time on their hands could write a program that uses a mutex object to check if there is another instance already running, and if there is, to pass it's file to that instance and then close, whereon the original instance will put that file in a queue and get to it once it's done processing its own file. a batch could do the trick using tasklist and find, too, but that's not as good of a solution as mutex

aaanyway, try this for your extract command registry value to get the right folder name:

"\path\to\7z.exe" x "%1" -o* -aou

this will create a new folder in the same directory as the source archive with the same name as the source archive (sans the file extension)

also, i added the -aou switch to automatically avoid filename conflicts (7z will append a number to the end of a file instead prompting you whether you want to overwrite or whatever)

happy unzipping lol

link|improve this answer
Works perfectly. Thanks! – schodge May 4 '11 at 21:35
feedback

The easy way: Install ExtractNow. You can configure it to do exactly what you want.

The hard way: Manual registry modification as follows...

  • Start regedit as administrator
  • Open HKCR\.7z and look at the (Default) value. Take note of what that is (in my case, as a PowerArchiver user, it's PASZIP)
  • Go to the registry key in HKCR named that. (in my case HKCR\PASZIP)
  • Under that key, expand the Shell sub-key
  • Set the (Default) value to the string extract
  • Create a new sub-key named extract
  • Set the (Default) value for the extract key to Extract to Folder
  • Create a new sub-key under extract named command
  • Set the (Default) value of the command key to cmd /c 7z.exe x "%1" -o"%~dpn1"

I think the above cmd /c command should be ok, according to the help from cmd.exe itself. The cmd /c command may be necessary to ensure that the command line gets expanded correctly. (Thanks to grawity for the tip.)

That should be it. Of course, this won't work if you have multiple files selected. If you want that to work, you need to create the following batch file:

@echo off
:top
if "%1"=="" goto :EOF
7z.exe x "%1" -o"%~dpn1"
shift
goto top

Now, follow the instructions above. In the very last step, set the (Default) value of the command key to C:\Path\To\File.bat %*

All of the registry modifications are untested from memory, but should be correct.

If you only want to make the changes on your user account instead of system-wide, modify HKCU\Software\Classes instead of HKCR. HKCR is a virtual key that's a union of HKLM\Software\Classes and HKCU\Software\Classes where the data in your account (HKCU) overrides the system-wide data (HKLM). Normally running regedit as an Administrator means that modifying HKCR alters system-wide data in HKLM.

link|improve this answer
Does %~dpn1 work in file associations? (It doesn't in Windows XP. Also, you forgot x for extension.) – grawity Mar 18 '11 at 20:46
1  
@grawity: You don't want the x in the output folder name. As for it working... That's a good question. I'll edit to address... – afrazier Mar 18 '11 at 20:48
Hm, good point. – grawity Mar 18 '11 at 21:12
So close, but not quite there yet. After playing with the code both afrazier and grawity provided, I have the default key value set as "C:\Program Files\7-Zip\7z.exe" x "%1" -o"%~dpn1" I wasn't getting any benefit from running cmd.exe that I could tell, and 7-zip's default open didn't bother with it. However, this is just unzipping to %~dpn1 in the same folder as the zip file. The \"%1.d\" gives a \filename.zip.d\ subdirectory in the same folder as the zip file, so it's closer, but not stripping off the extension. I've tried hybrids of the two, no luck. Any other suggestions? – schodge Mar 25 '11 at 1:43
You'll probably have to use a batch file. – afrazier Mar 25 '11 at 3:51
feedback

Pass parameters like this:

7z x "%1" -o"%1.d"

I recall hearing complaints about Windows 7 not allowing to directly edit file actions. I don't know if this is true or not... but if it is, save the following as a *.reg file and import it.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\7-Zip.7z\shell\extract]
@="Extract to folder"

[HKEY_CURRENT_USER\Software\Classes\7-Zip.7z\shell\extract\command]
@="7z.exe x \"%1\" -o\"%1.d\""
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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