如何在Windows PowerShell中比较两个.zip文件夹中的文件

Pay*_*son 2 powershell

我可以使用以下命令比较两个不同文件夹中的文件:

$test = get-childitem -recurse -path C:\test 
$test1 = get-childitem -recurse -path C:\test1
$counter = (diff $test $test1).count
Run Code Online (Sandbox Code Playgroud)

我想知道这两个文件夹有多少区别。这可行。

但是,现在我想比较两个.zip文件中的文件名。是否可以比较两个.zip文件中的文件,并且获得不同文件计数器的返回值?非常感谢。

Kei*_*ill 5

我已经在PowerShell V4上测试了.NET ZIP功能。我怀疑它可以在V3上运行,但不能在V2(或V1)上运行。

Add-Type -AN System.IO.Compression.FileSystem
$zip1 = [IO.Compression.ZipFile]::OpenRead("c:\test\test1.zip")
$zip2 = [IO.Compression.ZipFile]::OpenRead("c:\test\test2.zip")
$names1 = $zip1.Entries.FullName
$names2 = $zip2.Entries.FullName
$counter = (diff $names1 $names2).count
$zip1.Dispose()
$zip2.Dispose()
Run Code Online (Sandbox Code Playgroud)