繁体   English   中英

使用Powershell压缩文件

[英]zip files using powershell

这就是我试图使用Powershell压缩文件的方式。

  1. 整理超过xxx天的文件
  2. 将这些文件添加到zip文件中。
  3. 删除源文件。

我已经安装了Powershell_Community_Extensions,所以我使用Write-zip来完成这项工作。

$Source = "\\network\share"
$files = Get-ChildItem -Path $Source | Where-Object {$_.LastWriteTime -lt (get-date).AddDays(-62)}

$files | Write-Zip -OutputPath $Source\Archive.zip -EntryPathRoot $Source -Append -Quiet

Remove-Item $files -Force

问题:

  1. 我必须将-EntryPathRootWrite-zip一起使用,否则它将无法获取网络共享
  2. Remove-item也不会从网络共享中提取文件,它说"Remove-Item : Cannot find path 'C:\\Windows\\system32\\feb03.txt' because it does not exist." ,为什么它从C:\\Windows\\system32\\而不是\\\\network\\share删除文件
  3. Write-zip -append确实将文件添加到zip文件中,但它不仅在zip文件的根目录中添加了文件,它实际上在zip的根目录中创建了整个文件夹结构,并在此末尾添加了更新的过滤文件文件夹结构。 我只想将更新的过滤文件添加到该zip文件的根目录中。

有什么想法吗?

使用v5 *归档cmdlet:

$Source = '\\network\share'
$Files = Get-ChildItem -Path $Source |
    Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-62) }
Compress-Archive -Path $Files.FullName -DestinationPath $Source\Archive.zip -CompressionLevel Optimal -Update

$Files | Remove-Item -Force

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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