ExtractToDirectory with no folder

Welcome Forums General PowerShell Q&A ExtractToDirectory with no folder

Viewing 6 reply threads
  • Author
    Posts
    • #196127
      Participant
      Topics: 3
      Replies: 10
      Points: 55
      Rank: Member

      Hi

      I've got a zip file with this structure: test.zip -> Mark -> Today-> *.* ( every files)

      When I extract it , as a result I get this : test (folder) -> Mark (folder) -> Today ->*.* ( every files)

      How Can I get this structure : Today (folder) ->*.* (every files)

      I mean , I trying to avoid the first two folders creation.

      The best thing to be would be extract only the files without folders

      EDIT :

      I had to edit my question

    • #196139
      Participant
      Topics: 2
      Replies: 1687
      Points: 3,340
      Helping Hand
      Rank: Community Hero

      A pragmatic way would be to extract the archive as it is and afterwards move the folder "Mark" one directory up and delete the now empty folder "test". You might show the code you're using to extract your archive.

    • #196259
      Participant
      Topics: 3
      Replies: 10
      Points: 55
      Rank: Member

      A pragmatic way would be to extract the archive as it is and afterwards move the folder "Mark" one directory up and delete the now empty folder "test". You might show the code you're using to extract your archive.

      Thanks Olaf this is my old code

       {
           param([string]$zipfile, [string]$outpath)
           #[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
           Expand-Archive -Path $zipfile -DestinationPath $outpath
       }

       

      I've received an answer from StackOverflow , I want share with you
       function Unzip2 {
        param([string]$zipfile, [string]$out)
        $Archive = [System.IO.Compression.ZipFile]::OpenRead($zipfile)
        Foreach ($entry in $Archive.Entries.Where( { $_.Name.length -gt 0 })) {
            [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, "$out\$($entry.Name)")
        }
        $Archive.Dispose()
      }
      I discovered the pipeline concept and the '$_ '  . I'm going to study 😀
      Too bad it hasn't a graphic text like expand-archive !

       

    • #196271
      Participant
      Topics: 2
      Replies: 1687
      Points: 3,340
      Helping Hand
      Rank: Community Hero

      I've received an answer from StackOverflow , I want share with you ...

      It's been me asking you there why you're not using Expand-Archive. 😉

      Too bad it hasn't a graphic text like expand-archive ! ...

      What do you mean with "hasn't a graphic text"?

    • #196376
      Participant
      Topics: 3
      Replies: 10
      Points: 55
      Rank: Member

      Hello Olaf

      I had not been doing Expand- Archive because I didn't know it : I started writing my first script a week ago 😐

      Can I only download every files throught  Expand-Archive?

      When I talk about  "graphic text" I want to say that 'ExtractToFile' doesn't use progress bar or colored foreground/backcolor

      as the Expand-Archive does

      Thank

    • #196379
      Participant
      Topics: 2
      Replies: 1687
      Points: 3,340
      Helping Hand
      Rank: Community Hero

      Can I only download every files throught Expand-Archive?

      Unfortunately not. Expand-Archive will expand the archive just as it is. You could unzip the files to a temporary folder and move them afterwards to a final target location if that's needed – maybe for an automation task or so. 😉

      When I talk about "graphic text" I want to say that 'ExtractToFile' doesn't use progress bar or colored foreground/backcolor

      Ah ... I understand. And unfortunately the answer to this question is "No" as well. If that's crucial for you wou would need to create that functionality by yourself. But do you really need color to unzip some files? The files will be the same later – no mater what color the unzipper showed. 😉

    • #196382
      Participant
      Topics: 3
      Replies: 10
      Points: 55
      Rank: Member

      Can I only download every files throught Expand-Archive?

      Unfortunately not. Expand-Archive will expand the archive just as it is. You could unzip the files to a temporary folder and move them afterwards to a final target location if that's needed – maybe for an automation task or so. 😉

      When I talk about "graphic text" I want to say that 'ExtractToFile' doesn't use progress bar or colored foreground/backcolor

      Ah ... I understand. And unfortunately the answer to this question is "No" as well. If that's crucial for you wou would need to create that functionality by yourself. But do you really need color to unzip some files? The files will be the same later – no mater what color the unzipper showed. 😉

      +1

      Thank

       

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