简体   繁体   中英

How to compare files in two .zip folder in Windows PowerShell

I can compare files in two different folder with the commands:

$test = get-childitem -recurse -path C:\test 
$test1 = get-childitem -recurse -path C:\test1
$counter = (diff $test $test1).count

I would like to know how many differences between those two folders. This works.

However, now I would like to compare the filenames in two .zip files. Is it possible to compare the files inside two .zip files and I get a return value for the counter of different files? Thank you so much.

I have tested .NET ZIP functionality on PowerShell V4. I suspect it would work on V3 but not on V2 (or 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM