unzip a file one folder up in a directory tree

Welcome Forums General PowerShell Q&A unzip a file one folder up in a directory tree

Viewing 4 reply threads
  • Author
    Posts
    • #182592
      Participant
      Topics: 1
      Replies: 1
      Points: 15
      Rank: Member

      Hi,

      I'm having issue with the unzipping a file in a directory tree.

      Example scenario:

      C:\Source\project\bin\login.zip

      but in my scenario, I want to unzip my files in Project sub-folder

      Please let me know if it is possible in Powershell script, any line of code or a example will be helpful.

      Thanks,

       

    • #182613
      Senior Moderator
      Topics: 8
      Replies: 1141
      Points: 3,928
      Helping Hand
      Rank: Community Hero

      How are you trying to do it ? You can use Expand-Archive cmdlet (V 5 onwards) to unzip and use the -DestinationPath to your desired path.

    • #182634
      Participant
      Topics: 0
      Replies: 1
      Points: 8
      Rank: Member

      You can also use the CLI version of 7zip.

      Some code I use for unpacking:

      foreach ($arg in $args) {

          $file = Get-Item $arg
          & "C:\Program Files\7-Zip\7z.exe" x "$arg" -o"$($file.DirectoryName)"
          if ($LastExitCode -gt 0) {
              Write-Host "`nError: Exit code $LastExitCode`n" -ForegroundColor Red
              Pause
          }
      }

       

    • #183207
      Participant
      Topics: 3
      Replies: 137
      Points: 721
      Helping Hand
      Rank: Major Contributor

      & "C:\Program Files\7-Zip\7z.exe" x "$arg" -o"$($file.DirectoryName)"

      This is kind of invoking expression, but if you are looking for PowerShell to get this job done, then as @kvprasoon mentioned you need to use Expand-Archive cmdlet.

      Thank you.

    • #183411
      Participant
      Topics: 1
      Replies: 1
      Points: 15
      Rank: Member

      Thanks for the replies

      my issue is resolved

Viewing 4 reply threads
  • You must be logged in to reply to this topic.