【发布时间】:2018-05-20 16:48:01
【问题描述】:
这就是我试图用 powershell 来压缩文件。
- 整理出超过 xxx 天的文件
- 将这些文件添加到 zip 文件中。
- 删除源文件。
我安装了 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
问题:
- 我必须使用
-EntryPathRoot和Write-zip,否则它不会获取网络共享 - Remove-item 也不会从网络共享中提取文件,它说
"Remove-Item : Cannot find path 'C:\Windows\system32\feb03.txt' because it does not exist.",为什么它从C:\Windows\system32\删除文件而不是\\network\share -
Write-zip -append确实将文件添加到 zip 文件中,但它不只是在该 zip 文件的根目录中添加文件,它实际上在 zip 的根目录中创建了整个文件夹结构,并在该文件夹结构的末尾添加了更新的过滤文件.我只想将新过滤的文件添加到该 zip 文件的根目录中。
有什么想法吗?
【问题讨论】:
-
您使用的是哪个版本的 PowerShell?如果是 v5,则有内置的
*Archivecmdlet -
嗯....不知道,我在 v5 上。我现在就试试。
标签: powershell zip