How to zip only files and not the full path hierarchy with DotNetZip in powershell?

后端 未结 2 427
醉话见心
醉话见心 2020-12-15 20:24

I\'m trying to zip up log using DotNetZip and powershell. The files are in C:\\user\\temp\\logs When I loop through the logs in the directory and add them to the zip file,

2条回答
  •  眼角桃花
    2020-12-15 21:00

    Not tested, but I think this should work.

    [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\"
        set-location $directory
        $children = get-childitem *.log
        foreach ($o in $children)
        {
            $e = $zipfile.AddFile($o.Name)
           }
        }
        $zipfile.Save()
        $zipfile.Dispose()
    

提交回复
热议问题