brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Compress-Archive -Path decides whether the zip includes the root folder

CLI
~/tips/tip-windows-compress-archive-wildcard-root

Compress-Archive -Path C:\Reference -DestinationPath C:\Archives\Draft.zip

The folder path with or without a trailing star changes the zip layout.

Zipping a folder in PowerShell is one cmdlet, but the way you write the path decides what the archive looks like. The difference is a single asterisk.

Compress-Archive -Path C:\Reference -DestinationPath C:\Archives\Draft.zip

Per the documentation, this archive includes the Reference root directory and all its files and subdirectories. Unzip it and you get a Reference folder.

Compress-Archive -Path C:\Reference\* -DestinationPath C:\Archives\Draft.zip

With the asterisk the root directory is excluded, but all its files and subdirectories are zipped. The contents land directly where you unzip. A third form, C:\Reference\*.*, zips only the files in the root and leaves out subdirectories.

Two options worth knowing: -Update replaces older file versions in an existing archive and can add files to it, and -Force overwrites an existing archive. -CompressionLevel accepts Optimal (the default), Fastest and NoCompression.

There are real caveats. The cmdlet uses an API that limits the maximum file size to 2GB. It also ignores hidden files and folders, and the documentation recommends the .NET API when you need them in the archive. Finally, piping Get-ChildItem -Recurse into it can duplicate files, because every file and directory object is added separately.

None of this was run on a live Windows machine here. It follows the Microsoft documentation.

Further reading: Compress-Archive

More CLI tips wsl --shutdown wsl --distribution <Distribution Name> --user <User Name> wsl --terminate <Distribution Name> rg -o -r '$2' '"(GET|POST) (\S+)' access.log redis-cli --json HGETALL user All CLI tips (60) All topics

Link