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?
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.
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. The one you're using looks like the PowerShell Community Extensions version written by Oisin. 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. You can pick up those versions here and here.