简体   繁体   English

Powershell Write-Zip部分文件夹树

[英]Powershell Write-Zip Partial Folder Tree

I have a folder structure that looks like this: 我有一个看起来像这样的文件夹结构:

-Daily Logs
  -Script1Logs
  -AnotherScriptLogs
  -ThirdScriptLogs

I would like to zip all the folders underneath "Daily Logs" and retain the same folder structure. 我想压缩“每日日志”下面的所有文件夹,并保留相同的文件夹结构。

Is there a way to zip the folders in one shot without going through each one individually? 有没有一种方法可以将文件夹压缩成一张快照,而不必逐一浏览? Also, can the zip file include only the file structure shown above instead of the entire path to the log folders? 另外,该zip文件是否可以仅包括上面显示的文件结构,而不包括日志文件夹的整个路径?

This is what I am using to zip the Daily Logs folder, but it does not zip the sub folders and it includes the entire path to the daily logs folder as part of the folder structure inside the zip file. 这就是我用来压缩Daily Logs文件夹的内容,但是它没有压缩子文件夹,它包含了每日日志文件夹的完整路径,这是zip文件中文件夹结构的一部分。

If (!(Test-Path $ARCHIVELOGFOLDER\$ARCHIVELOGFILE)) { 
    Write-Zip $file.FullName $ARCHIVELOGFOLDER\$ARCHIVELOGFILE
    Write-Zip -Path $files -OutputPath $ArchiveFile -Append -FlattenPaths -IncludeEmptyDirectories -Quiet -Level 9
} 

Write-Zip is not a native PowerShell cmdlet. Write-Zip不是本机PowerShell cmdlet。 The one you're using looks like the PowerShell Community Extensions version written by Oisin. 您正在使用的版本类似于Oisin编写的PowerShell Community Extensions版本。 It will preserve paths and not use a full path if used like so: 如果像这样使用,它将保留路径并且不使用完整路径:

C:\InetPub> Write-Zip -Path Logs -OutputPath logs.zip -IncludeEmptyDirectories

Note that there have been several bugs fixed in the latest release candidates for 2.1 and 3.0. 请注意,最新版本的候选版本2.1和3.0中已修复了多个错误。 You can pick up those versions here and here . 您可以在此处此处获取这些版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM