Menu

Extract all, but ignore top folder?

2021-12-05
2023-01-31
  • J. Scott Elblein

    Let's see if I can explain this properly ...

    When you download most releases from GitHub in .zip format, the contents will look something like this:

    SomeProject_1.2.3.4 <top folder> <--- ignore
        - <some folder> <--- extract everything from here on down ---->
        - <some folder>
        - <some folder>
        - <some folder>
        - <bunch of files below this>
    

    I want to extract everything under that top folder, but not create that top folder when extracted. So, for example, I could make a folder named "blah", and 7z would extract just the contents under that top folder, to the "blah" folder.

    Is there a cline switch that does this?

    TIA

     

    Last edit: J. Scott Elblein 2021-12-05
    • mathlete

      mathlete - 2023-01-31

      I just found out that tar is now available on Windows. For the setup I outlined below, the following works as desired:

      mkdir test
      tar -xf folder.tar --strip-components=1 -C test
      

      This works on .zip too. In fact, it also works on .tar.gz.

       
  • Igor Pavlov

    Igor Pavlov - 2021-12-05

    There is no switch now.
    But you can extract folder with full path and then move it with os shell command.

     
  • mathlete

    mathlete - 2023-01-31

    I'm trying to do the same thing with .tar files, and I can get halfway there with the following:

    7z x folder.tar -t* -otest
    

    The problem is that <top folder> still appears in test (files included), even when I do the following:

    7z x folder.tar -t* -spe -otest
    

    Interestingly, -t* does nothing for .zip files: <top folder> is the only thing created in test.
    @ipavlov are these bugs?

     
    • Igor Pavlov

      Igor Pavlov - 2023-01-31

      -spe eliminates top folder if it has same name as name of archive.

       
      • mathlete

        mathlete - 2023-01-31

        Thanks for the clarification, but unfortunately, renaming folder.tar to topFolder.tar does not help (even if I rebuild the .tar instead of simply renaming it).

        In fact, I'm now finding that -t* no longer brings up the content of topFolder, even when I switch back to folder.tar - topFolder is now the only object in test no matter what I do.

         
        • Igor Pavlov

          Igor Pavlov - 2023-01-31

          -t* is not related to tar at all.
          -t* allows to open top level format from vmdk or vhd instead of default smart nested archive open operation.

          -spe is working with -oname switch.
          If root folder in archive has same name as last part name in -opath\name switch, it will remove that root dir part.
          So you will have no duplication name\name\ in extrated paths.
          It's common case in 7-zip usage.
          You have folder name with files.
          You select that folder and create name.tar from that foder.
          And then you extract name.tar no default name path (that uses -oname switch).
          So we needed that eliminate feature (-spe) to eliminate that duplication of name for that most common case.

           

          Last edit: Igor Pavlov 2023-01-31

Log in to post a comment.