3

按照技术食谱的示例,我设法列出了 ZIP 文件的内容(使用 7-Zip:

FOR /F "tokens=* delims=" %%A in ('dir /b /s *.zip') do (7z.exe l -r "%%A" >> listing.txt)

但是,这只是将 ZIP 文件的整个目录结构转储到一个文本文件(称为 list.txt)中。

我只想列出最高级别目录的目录名称,例如

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

我只希望文本文件包含:

  • 目录一
  • 目录二
  • 目录三

谁能建议我如何实现这一目标?

4

2 回答 2

2

7z 似乎没有内置键,但是你可以做一些批处理脚本(这个在文件名中搜索斜杠,如果没有找到斜杠则显示行):

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!
  )
)
于 2013-04-24T10:46:03.463 回答
0
7z.exe l -r "File.7z" | FINDSTR "[0-9].D....\>" | FIND /V "\"

使用第一个 Findstr,我们过滤输出,得到一个仅包含 dirs 的列表(“D”属性)。

通过第二个查找,我们从输出中删除包含反斜杠的路径(文件夹\子文件夹)。

如何将其与大量拉链一起使用:

@echo off

(For /R %%# in (*.zip) do (

    Echo File: "%%#" | MORE

    For /F "Tokens=5,*" %%A in (
        '7z.exe l -r "%%#" ^| FINDSTR "[0-9].D....\>" ^| FIND /V "\"'
    ) do (
        Set /A "Num+=1"
        Call Echo %%NUM%%.0: %%B
    )

    Set /A "Num=0"
    Echo+

))>"listing.txt"

Pause&Exit

测试结构:

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2013-04-24 13:02:29 ....A          274          167  ..bat
2013-04-24 13:02:29 ....A          274               1\2\2.bat
2013-04-24 13:02:29 ....A          274               a\b\c\c.bat
2013-04-24 13:12:45 D....            0            0  a\b\c
2013-04-24 13:12:37 D....            0            0  a\b
2013-04-24 13:12:33 D....            0            0  a
2013-04-24 13:12:50 D....            0            0  1\2
2013-04-24 13:12:24 D....            0            0  1
------------------- ----- ------------ ------------  ------------------------
                                   822          167  3 files, 5 folders

收到的输出:

File: "C:\Users\Administrador\Desktop\Nueva carpeta\x.7z" 

1.0: a
2.0: 1
于 2013-04-24T11:21:58.770 回答