When zipping folders using Compress-Archive it skips all hidden files.
The Documentation page tells us that this cmdlet uses Microsoft .NET Framework API System.IO.Compression.ZipArchive in the background.
Is there some way to force it to archive hidden files? I cannot find this issue documented anywhere. I tried -Force
for the heck of it, didn't help.
My current workaround is to use Set-FileAttribute
to remove the hidden attribute before zipping.
I replaced Compress-Archive
with \[System.IO.Compression.ZipFile]::CreateFromDirectory(sourceDirectoryName, destinationArchiveFileName)
and found (on macOS at least) that the ZIP-file included a directory that starts with .
(which is one way to hide a directory/file on macOS). This is using PowerShell 7.2.
I've just had the same issue and this is how I got aroung it
# WARNING: This only works on a windows based powershell core terminal instance.
# In a linux based powershell core instance the .dot files are not included in
# the final archive when using the -Filter example
# This will include .files like .gitignore
Get-ChildItem -Path . -Filter *.* | Compress-Archive -DestinationPath dist.zip
# This will include .dot files like .gitignore and any that are hidden like .git
Get-ChildItem -Path . -Force | Compress-Archive -DestinationPath dist.zip
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With