相关疑难解决方法(0)

如何在PowerShell中使用DotNetZip仅压缩文件而不压缩完整路径层次结构?

我正在尝试使用DotNetZip和powershell压缩日志.这些文件位于C:\ user\temp\logs当我遍历目录中的日志并将它们添加到zip文件时,当我只想要日志文件时,我最终得到了文件夹层次结构和日志文件.

因此拉链最终包含:

-user
  ?temp  
    ?logs
       ?log1.log
        log2.log
        log3.log
Run Code Online (Sandbox Code Playgroud)

当我想要包含的zip文件是:

log1.log
log2.log
log3.log
Run Code Online (Sandbox Code Playgroud)

这是我正在运行以测试的脚本:

[System.Reflection.Assembly]::LoadFrom("c:\\\User\\bin\\Ionic.Zip.dll");
$zipfile = new-object Ionic.Zip.ZipFile("C:\user\temp\logs\TestZIP.zip");

$directory = "C:\user\temp\logs\"
$children = get-childitem -path $directory
foreach ($o in $children)
{
   if($o.Name.EndsWith(".log")){
      $e = $zipfile.AddFile($o.FullName)
   }
}
$zipfile.Save()
$zipfile.Dispose()
Run Code Online (Sandbox Code Playgroud)

powershell dotnetzip

16
推荐指数
1
解决办法
1万
查看次数

标签 统计

dotnetzip ×1

powershell ×1