How to extract files to same folder

Help
2013-09-05
2013-09-06
  • Onno Wassenaar
    Onno Wassenaar
    2013-09-05

    Hi all,

    I have been trying this for a while now, but I can't figure it.

    How can I extract a zip file to a folder with the name of that file. I want to use the command line to do this.

    I have c:\test\zip.7z and I want to extract it to c:\test\zip\

     
  • Ghost Templar
    Ghost Templar
    2013-09-06

    You can't do this with the 7z program directly, but you can wrap it in a script to do so. Make a file called extract.bat or whatever you want to call it and put this line in:

    for /F %%i in ("%1") do "C:\Program Files\7-Zip\7z.exe" x %%i -o%%~ni

    If you're using 32-bit 7-Zip instead of 64-bit, replace Program Files with Program Files (x86)

    Now you can run from the command line something like:

    extract zip.7z

    and it will determine the output folder name by cropping the extension from your input filename. Slightly messy because it prints the for command as well, but it does the job at least.