How to unzip a file and copy it to a specific location using 7zip?

I just tried opening the zip archive in powershell and moving the files to it in a specific place. but it always moves only 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\} 
+4
source share
4 answers

I believe the correct answer should be something like this:

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

Alroc was almost right, but $_.fullname between quotation marks did not work, and it lacked the -o option for 7z. I use 7z.exe instead of 7zg.exe , works fine this way.

Reference information can be found here: http://sevenzip.sourceforge.jp/chm/cmdline/ Basically, x means "eXtract" and -o for "Output directory"

+5
source

Function to get the path to 7z.exe

 function Get-7ZipExecutable { $7zipExecutable = "C:\Program Files\7-Zip\7z.exe" return $7zipExecutable } 

Function for zip folders in which the destination is set to

 function 7Zip-ZipDirectories { param ( [CmdletBinding()] [Parameter(Mandatory=$true)] [System.IO.DirectoryInfo[]]$include, [Parameter(Mandatory=$true)] [System.IO.FileInfo]$destination ) $7zipExecutable = Get-7ZipExecutable # All folders in the destination path will be zipped in .7z format foreach ($directory in $include) { $arguments = "a","$($destination.FullName)","$($directory.FullName)" (& $7zipExecutable $arguments) $7ZipExitCode = $LASTEXITCODE if ($7ZipExitCode -ne 0) { $destination.Delete() throw "An error occurred while zipping [$directory]. 7Zip Exit Code was [$7ZipExitCode]." } } return $destination } 

File decompression function

 function 7Zip-Unzip { param ( [CmdletBinding()] [Parameter(Mandatory=$true)] [System.IO.FileInfo]$archive, [Parameter(Mandatory=$true)] [System.IO.DirectoryInfo]$destinationDirectory ) $7zipExecutable = Get-7ZipExecutable $archivePath = $archive.FullName $destinationDirectoryPath = $destinationDirectory.FullName (& $7zipExecutable x "$archivePath" -o"$destinationDirectoryPath" -aoa -r) $7zipExitCode = $LASTEXITCODE if ($7zipExitCode -ne 0) { throw "An error occurred while unzipping [$archivePath] to [$destinationDirectoryPath]. 7Zip Exit Code was [$7zipExitCode]." } return $destinationDirectory } 
+1
source

I don’t have 7Zip for testing, but I think it’s not because you don’t tell 7Zip what to work for, and you yourself move your ZIP file to the destination. Try the following:

 Get-ChildItem C:\zipplayground\*.zip | % {invoke-expression "C:\Program Files (x86)\7-Zip\7zG.exe x $_.FullName c:\unzipplayground\";} 
0
source

If you want to avoid using open source exe / dll like 7zip, install the PSCX module for powershell and use expand-archive. Please note that PSCX requirements are at least .net 4 (I use 4.5) and powershell 3.0

http://pscx.codeplex.com/

0
source

Source: https://habr.com/ru/post/1494936/


All Articles