List zip file's contents using 7zip command line with non-verbose machine-friendly output

13,547

7z v15.xx introduced some new switches:

  • -slt - show technical information for l command
  • -ba - suppress headers; undocumented.

The output with these switches set looks like this:

D:\TruLaLa> 7z l -ba -slt test.7z
Path = 2.msi
Size = 2005506
Packed Size = 638340
Modified = 2009-04-16 23:00:00
Attributes = 
CRC = B6FFF2FF
Encrypted = -
Method = LZMA:3m
Block = 0

Path = 1.doc
Size = 35328
Packed Size = 
Modified = 2008-12-06 23:00:00
Attributes = 
CRC = C041B41F
Encrypted = -
Method = LZMA:3m
Block = 0
...
Path = 2+.log
Size = 303250
Packed Size = 
Modified = 2015-03-13 18:57:32
Attributes = A
CRC = 5C738A96
Encrypted = -
Method = PPMD:o32:mem192m
Block = 1
...
Path = 3.txt
Size = 0
Packed Size = 0
Modified = 2015-10-13 01:46:41
Attributes = A
CRC = 
Encrypted = -
Method = 
Block = 

This format is definitely more readable for us, robots.)

Share:
13,547

Related videos on Youtube

ivanatpr
Author by

ivanatpr

Updated on September 18, 2022

Comments

  • ivanatpr
    ivanatpr over 1 year

    Is there a way, in windows, to use 7z.exe's list command such that the copyright heading, file information, and column headers are skipped and you're left with just a terse machine-readable list of files within the archive?

    Right now I get this

    >7z.exe l Test.zip
    
    7-Zip [64] 9.38 beta  Copyright (c) 1999-2014 Igor Pavlov  2015-01-03
    
    Listing archive: Test.zip
    
    --
    Path = Test.zip
    Type = zip
    Physical Size = 29966218
    
       Date      Time    Attr         Size   Compressed  Name
    ------------------- ----- ------------ ------------  ------------------------
    2015-11-01 23:52:49 ....A     14887917     14256660  01 - Bitter Sweet Symphony.mp3
    2015-10-30 22:45:48 ....A     16567208     15709214  06 - Hallelujah.mp3
    ------------------- ----- ------------ ------------  ------------------------
    2015-11-01 23:52:49           31455125     29965874  2 files
    
    Kernel  Time =     0.000 =    0%
    User    Time =     0.000 =    0%
    Process Time =     0.000 =    0%    Virtual  Memory =      2 MB
    Global  Time =     0.010 =  100%    Physical Memory =      6 MB
    

    What I want to see is just this:

    >7z.exe l Test.zip
    
    2015-11-01 23:52:49 ....A     14887917     14256660  01 - Bitter Sweet Symphony.mp3
    2015-10-30 22:45:48 ....A     16567208     15709214  06 - Hallelujah.mp3
    
    • Admin
      Admin over 8 years
      I don't think there's an in-built option in 7-zip... Is there any specific reason you have to use 7-zip? Are alternative utilities/methods acceptable? Which version of Windows is in question?
    • Admin
      Admin over 8 years
      In a larger scope... how is your example output any more 'machine readable', than the normal output? To me it's not any easier, as the fields don't seem delimited consistently, so the parsing/processing you'll probably have to do to the output anyway (to deal with that) could easily include skipping the first and last 'X' amount of lines... So why not just parse/process 7-zip's output (via scripting or whatever) before passing it along to the next step?
    • Admin
      Admin over 8 years
      7zip is ideal (but not necessary) because it works with many different types of archive formats and the list command gives just the right set of information that I need.
    • Admin
      Admin over 8 years
      I realize I can parse the output to remove the unwanted lines, I just wanted to ask if there was a built-in way of doing this before going that route because the sum line's formatting is very similar to the regular file list lines so the regex is nontrivial.
    • Admin
      Admin over 8 years
      I wouldn't bother with Regex to remove the lines, as they will probably always be the same number/amount at top and bottom. But regardless, if your question is specifically "Can 7-zip do this?" then I'm pretty certain the answer is simply "No". If you want a solution to your actual problem, then we'll need more info so we can provide a non-7-zip solution.