Search code examples
powershell7zip

How to Unzip a file and copy it to specific location with 7zip?


I just tried to open a zip archive in powershell and move the files in it to a specific location. but it always moves just the zip folder. What am I doing wrong ?

This is what I have now :

Get-ChildItem C:\zipplayground\*.zip | % {"C:\Program Files (x86)\7-Zip\7zG.exe";
Move-Item $_ C:\unzipplayground\}

Solution

  • I believe the right answer should be something like that:

    Get-ChildItem C:\zipplayground\*.zip | % {& "C:\Program Files\7-Zip\7z.exe" "x" $_.fullname "-oC:\unzipplayground"}
    

    Alroc was almost right, but $_.fullname between quotes doesn't work, and he was missing the -o parameter for 7z. I'm using 7z.exe instead of 7zg.exe, works fine this way.

    For reference, the command line help can be found here: http://sevenzip.sourceforge.jp/chm/cmdline/ Basically, x stands for 'eXtract' and -o for 'Output directory'