powershell - 如何将.xml文件复制到zip文件夹?

标签 powershell zip

我正在尝试将.xml文件移动或复制到zip文件夹中。

Move-Item-Path "C:\Users\1469\Desktop\folder1\archive.xml" -Destination "C:\Users\1469\Desktop\*.zip" -Force

但是此代码不起作用。请帮我!

最佳答案

您在该行中有一个错字(Move-Item-Path应该是Move-Item -Path)。但是,您不能在目标路径中使用通配符,也不能使用Move-Item将文件移动到zip文件中。这样做只会用XML文件覆盖zip文件。

您需要 Shell.Application COM对象才能将文件添加到zip文件中:

$zip = 'C:\Users\1469\Desktop\your.zip'
$xml = 'C:\Users\1469\Desktop\folder1\archive.xml'

(New-Object -COM Shell.Application).NameSpace($zip).CopyHere($xml)

请注意,该zip文件必须已经存在。它不会自动创建。

关于powershell - 如何将.xml文件复制到zip文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18659298/

相关文章:

带有 ComputerName 的 powershell Get-Process 缺少路径

azure - 我的 Azure 订阅 + IAM 访问控制凭证中的所有资源列表

zip - Monotouch - ICSharpCode.SharpZipLib 出现错误

C++ 将文件权限添加到 Zip 文件

linux - 失败时如何查看AWS Elastic Beanstalk部署过程日志

powershell - 复制项目并覆盖?

csv - PowerShell - Import-Csv - 按位置引用列

node.js - winston 每日轮换删除 .GZIP 文件

windows - 如何压缩文件名中包含今天日期的文件夹?

powershell - Set-ExecutionPolicy 哪个是正确的?