[英]zip files using powershell
This is what I am trying to do with powershell for zipping files. 这就是我试图使用Powershell压缩文件的方式。
I have Powershell_Community_Extensions installed so I use Write-zip
to do the job. 我已经安装了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
Issues: 问题:
-EntryPathRoot
with Write-zip
, otherwise it wont pick up network share -EntryPathRoot
与Write-zip
一起使用,否则它将无法获取网络共享 "Remove-Item : Cannot find path 'C:\\Windows\\system32\\feb03.txt' because it does not exist."
"Remove-Item : Cannot find path 'C:\\Windows\\system32\\feb03.txt' because it does not exist."
, why it deleting file from C:\\Windows\\system32\\
instead of \\\\network\\share
C:\\Windows\\system32\\
而不是\\\\network\\share
删除文件 Write-zip -append
did add files into the zip file, but it did not just add files in the root of that zip file, it actually created entire folder structure in the root of the zip and added newer filtered files in the end of that folder structure. Write-zip -append
确实将文件添加到zip文件中,但它不仅在zip文件的根目录中添加了文件,它实际上在zip的根目录中创建了整个文件夹结构,并在此末尾添加了更新的过滤文件文件夹结构。 I just want to add the newer filtered files into root of that zip file. Any idea please? 有什么想法吗?
Utilizing the v5 *Archive cmdlets: 使用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.