Microsoft.PowerShell.Archive icon indicating copy to clipboard operation
Microsoft.PowerShell.Archive copied to clipboard

Compress-Archive should have a -SkipBaseDirectory switch

Open Jaykul opened this issue 8 years ago • 2 comments

When I run

Compress-Archive $pwd -Destination ..\Compressed.zip

I always get a (redundant) single top-level folder in the zip

We need an option to not create that top level folder.

Note that this does not work:

Get-ChildItem $pwd | Compress-Archive -Destination ..\Compressed.zip

Because the resulting zip will be missing any empty subfolders of $pwd

Jaykul avatar Oct 03 '17 20:10 Jaykul

My current workaround is to use:

[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
[System.IO.Compression.ZipFile]::CreateFromDirectory('c:\tmp\somedir', 'c:\tmp\foo.zip', 'Optimal', $false)

sba923 avatar Jan 11 '20 10:01 sba923

Duplicating the root folder is problematic with the .Nupkg format.

I have tried the workaround of @sba923 but the compressed file cannot be expanded on some clients by chocolatey packages.

When I zip the same folder with Right-Click\Send To\Compressed (Zipped) folder it works fine, but I cannot automate this...

fullenw1 avatar Dec 04 '20 20:12 fullenw1