Listing the contents of a ZIP file
12,453
7z doesn't seem to have builtin key for this, however you can do some batch scripting (this one searches for slash in file name and displays line if slash not found) :
7z.exe l -r archive.zip > lines.txt
@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=*" %%a in (lines.txt) do (
set line=%%a
set srch=!line:\=!
if "!line!" == "!srch!" (
echo !line!
)
)
Related videos on Youtube
Author by
JHarley1
Updated on June 04, 2022Comments
-
JHarley1 almost 2 years
Following an example of tech-recipes I have managed to list the contents of a ZIP file (using 7-Zip:
FOR /F "tokens=* delims=" %%A in ('dir /b /s *.zip') do (7z.exe l -r "%%A" >> listing.txt)
However, this just dumps out the entire directory structure of the ZIP file into a text file (called listing.txt).
I only want to list the directory names of the highest level directories e.g.
Example.Zip
7-Zip 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18 Listing archive: C:\Users\Test\Desktop\7zip\Demo.zip -- Path = C:\Users\Test\Desktop\7zip\Demo.zip Type = zip Physical Size = 1252 Date Time Attr Size Compressed Name ------------------- ----- ------------ ------------ ------------------------ 2013-04-24 13:12:26 D.... 0 0 Directory Three\Sub Folder One 2013-04-24 13:13:00 D.... 0 0 Directory Three\Sub Folder Three 2013-04-24 13:12:54 D.... 0 0 Directory Three\Sub Folder Two 2013-04-24 13:12:26 D.... 0 0 Directory Two\Sub Folder One 2013-04-24 13:13:00 D.... 0 0 Directory Two\Sub Folder Three 2013-04-24 13:12:54 D.... 0 0 Directory Two\Sub Folder Two 2013-04-24 13:12:26 D.... 0 0 Directory One\Sub Folder One 2013-04-24 13:13:00 D.... 0 0 Directory One\Sub Folder Three 2013-04-24 13:12:54 D.... 0 0 Directory One\Sub Folder Two ------------------- ----- ------------ ------------ ------------------------ 0 0 0 files, 9 folders
I would only want the text file to contain:
- Directory One
- Directory Two
- Directory Three
Can anyone suggest how I could achieve this?
-
JHarley1 about 11 yearsWhen I run the batch file - I get a text file containing 'File: "{filename}.zip". Can you tell me about the significance of '5' for tokens?
-
ElektroStudios about 11 yearsThe script runs good and prints the filanames good, please explain the filename problem with another example to understand it. A token is a string delimitted by a {space} (By default), so with "5,*" tokens we are spliting each line in 5+1 strings. 6 tokens 'cause 6 columns, one: 2013-04-24 two: 13:12:24 three: D.... four: 0 five: 0 six: {Folder name}. then I print the sixth token to the textfile.
-
JHarley1 about 11 yearsFor some reason by 'raw output' does not have a 'Date' or 'Time' - would this be causing the issue?
-
ElektroStudios about 11 yearsIf date or time values are empty spaces then yes that's the problem. I suppossed all the values on date/time columns ever would be filled. splitting the lines is the best choice but have that inconvenient... let me think about it.
-
ElektroStudios about 11 yearsBut that example has date and time values or maybe I understanded bad what you will said? if the problem is you don't want the first folder name "demo" then you maybe will consider to compress and unchecking the option "preserve directory root" in 7zip, then "demo" root will not appear more when listing and the script will run ok.
-
JHarley1 about 11 yearsI have updated the structure of the ZIP as suggested - I am still just getting File: "C:\Users\Test\Desktop\7zip\Demo.zip". Maybe its an issue with my version of 7-Zip.