1

I'm trying to create one Zip-file which contains everything in that directory (files & folders) and that preserves the directory structure.

By looking around on the net I see that lots of people have issues with this. So to make it easy on myself I installed the modules from pscx which contain the CmdLet Write-Zip.

Folder structure

- S:\TopFolder
- S:\TopFolder\Folder1
- S:\TopFolder\Folder1\SubFolder1
- S:\TopFolder\Folder1\SubFolder1\Stuff1.txt
- S:\TopFolder\Folder2
- S:\TopFolder\Folder2\SubFolder2
- S:\TopFolder\Folder2\SubFolder2\Stuff2.txt

Tested code

$Test = Get-ChildItem -Recurse 'S:\TopFolder\*'
Write-Zip -Path $Test -OutputPath 'S:\Zippie.zip' -IncludeEmptyDirectories

$Test = Get-ChildItem -Recurse 'S:\TopFolder'
Write-Zip -Path $Test -OutputPath 'S:\Zippie.zip' -IncludeEmptyDirectories

Result in 'Zippie.zip'

SubFolder1
SubFolder1\Stuff1.txt
SubFolder2
SubFolder2\Stuff2.txt

As you can see it's not sticking to the correct folder structure as Folder1 and Folder2 are missing. Is there something obvious I'm missing here? Because this issue has been reported as fixed and verified.

Thank you for your help.

DarkLite1
  • 13,637
  • 40
  • 117
  • 214

1 Answers1

5

After getting some help from Dave Wyatt on PowerShell.org it's fixed now.

The correct syntax seems to be:

Get-ChildItem -Recurse 'S:\TopFolder' |
Write-Zip -OutputPath 'S:\Test\Zippie.zip' -IncludeEmptyDirectories -EntryPathRoot 'S:\TopFolder'
DarkLite1
  • 13,637
  • 40
  • 117
  • 214
  • Just in case anyone gets the same problem as I did running this or a similar script - EntryPathRoot is case sensitive to path that is piped into it. So `Get-ChildItem -Recurse 'S:\TopFolder' | Write-Zip -OutputPath 'S:\Test\Zippie.zip' -IncludeEmptyDirectories -EntryPathRoot 's:\topfolder` will produce an error saying "Skipping [file]. It is not under the entry path root [path]. – Gavin Ward Nov 02 '15 at 15:08