列出 ZIP 文件的内容 [英] Listing the contents of a ZIP file

查看:44
本文介绍了列出 ZIP 文件的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

然而,这只是将 ZIP 文件的整个目录结构转储到一个文本文件中(称为 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.

示例.Zip

7-Zip 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Listing archive: C:UsersTestDesktop7zipDemo.zip

--
Path = C:UsersTestDesktop7zipDemo.zip
Type = zip
Physical Size = 1252

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2013-04-24 13:12:26 D....            0            0  Directory ThreeSub Folder One
2013-04-24 13:13:00 D....            0            0  Directory ThreeSub Folder Three
2013-04-24 13:12:54 D....            0            0  Directory ThreeSub Folder Two
2013-04-24 13:12:26 D....            0            0  Directory TwoSub Folder One
2013-04-24 13:13:00 D....            0            0  Directory TwoSub Folder Three
2013-04-24 13:12:54 D....            0            0  Directory TwoSub Folder Two
2013-04-24 13:12:26 D....            0            0  Directory OneSub Folder One
2013-04-24 13:13:00 D....            0            0  Directory OneSub Folder Three
2013-04-24 13:12:54 D....            0            0  Directory OneSub Folder Two
------------------- ----- ------------ ------------  ------------------------
                                     0            0  0 files, 9 folders

我只希望文本文件包含:

I would only want the text file to contain:

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

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

Can anyone suggest how I could achieve this?

推荐答案

7z 似乎没有为此提供内置密钥,但是您可以执行一些批处理脚本(这个在文件名中搜索斜杠并在斜杠时显示行未找到):

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!
  )
)

这篇关于列出 ZIP 文件的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆