我想查找名称为'test'的所有文件夹,并将它们压缩到具有不同名称的单个文件夹中,当然。找到所有特定的文件夹并将它们压缩
我设法做一些代码:
$RootFolder = "E:\"
$var = Get-ChildItem -Path $RootFolder -Recurse |
where {$_.PSIsContainer -and $_.Name -match 'test'}
#this is assembly for zip functionality
Add-Type -Assembly "System.IO.Compression.Filesystem"
foreach ($dir in $var) {
$destination = "E:\zip\test" + $dir.Name + ".zip"
if (Test-Path $destination) {Remove-Item $destination}
[IO.Compression.Zipfile]::CreateFromDirectory($dir.PSPath, $destination)
}
它给了我一个错误:
Exception calling "CreateFromDirectory" with "2" argument(s): "The given path's format is not supported."
我想知道,究竟是通过我的$dir
的路径的正确途径。
谢谢! '全名'propery令我困惑,我没有怀疑这实际上是一条路! – Stefan0309