【发布时间】:2020-05-17 16:24:13
【问题描述】:
我在 Win10 中以两种方式从目录创建 zip 文件。
第一种方法使用“右键单击...发送到...压缩(压缩)文件夹”
第二种方法使用Powershell Compress-Archive。我想使用 Powershell 自动化这个过程。
zip 文件是要导入 Arduino IDE 的库。
第一种方法将正确导入 Arduino IDE。第二种方法无法正确导入。
在你说这是一个 Arduino 问题之前,请继续阅读。
所以为了确保文件相同,我使用 Powershell 为这两个文件生成了 MD5 校验和。 令我惊讶的是他们是不同的!
我发现的唯一区别是创建的 zip 文件的大小。它们是从相同的源文件创建的。
为什么它们不同?我可以通过文件资源管理器中的“双击并全部提取”手动解压缩这两个文件
感谢您的任何建议/帮助。约翰。
这是 powershell 脚本的输出...
目录:C:\file1
模式 LastWriteTime 长度 名称
---- ------------- ------ ----
-a---- 05/16/2020 17:18 1948 t_OS.zip
算法:MD5 哈希:19249C2BB9B50E827A77F7A2952EFF6D 路径:C:\file1\t_OS.zip
目录:C:\file2
模式 LastWriteTime 长度 名称
---- ------------- ------ ----
-a---- 05/16/2020 19:23 1724 t_OS.zip
算法:MD5 哈希:2BF7B111F54FC0555E6CA64719AD350F 路径:C:\file2\t_OS.zip
...
#
# sourceFiles are what I need to be zipped. It contains the
# directory t_OS and I need to create t_OS.zip
#
$sourceDir = "C:\sourceFiles"
$sourceFiles = "C:\sourceFiles\t_OS"
# file1 zip was created by right-clicking on the directory t_OS
# in the $sorceDir and selecting Send To, then
# Compressed (zipped) folder. This file was then moved to...
#
$file1 = "C:\file1\t_OS.zip"
# file2 zip is created by powershell using Compress-Archive below.
$file2 = "C:\file2\t_OS.zip"
Get-ChildItem -LiteralPath $sourceDir -Name -Recurse
If (Test-Path $file2) {Remove-Item $file2}
Compress-Archive -DestinationPath $file2 -CompressionLevel Fastest -Path $sourceFiles
Get-ItemProperty -LiteralPath $file1
Get-FileHash -Path $file1 -Algorithm MD5
Get-ItemProperty -LiteralPath $file2
Get-FileHash -Path $file2 -Algorithm MD5
...
【问题讨论】:
-
PowerShell 可能使用其他压缩方法或其他压缩级别。 ZIP 可能非常不同 (see more)。
-
您找到解决方案了吗?我现在也遇到了同样的问题。
-
@Reaver,我没有找到解决方案,但我确实找到了问题所在。查看这两个 zip 文件,在 Arduino IDE 预期的 powershell zip 文件中缺少一个目录行。在我的示例中,powershell 创建的 zip 缺少 t_OS/src。
标签: powershell zip md5 compress-archive