Skip to content

SamiLehtinen/CompressTarZstd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

CompressTarZstd

A tiny, single-file PowerShell script that adds a "Compress to tar.zst" entry to the Windows Explorer right-click menu for folders.

It uses the tar.exe shipped with Windows 10/11, which supports zstd natively via the -a (auto-compress by extension) flag — no third-party tools, no dependencies, no DLLs.

Right-click  stuff\   →  Compress to tar.zst   →   stuff.tar.zst

Features

  • Single file. One script does install, uninstall, and the actual compression payload.
  • No dependencies. Uses built-in tar.exe (Windows 10 1803+ / Windows 11).
  • Per-user install. Writes only to HKCU — no admin rights needed.
  • Clean archives. Archives the folder's contents as ./..., not leaf/..., so extractors don't double-nest.
  • Quiet by default. Runs hidden; logs only when something goes wrong.
  • Self-rotating log in %TEMP%, capped at 1 MB, deleted on success.
  • Robust path handling. Works around PowerShell 5.1's Split-Path -LiteralPath -Leaf parameter-set bug, and Explorer's quoting quirks (paths with spaces, apostrophes, trailing backslashes).

Requirements

  • Windows 10 (1803+) or Windows 11 — must have C:\Windows\System32\tar.exe.
  • Windows PowerShell 5.1 (preinstalled) or PowerShell 7+.

You can verify tar.exe supports zstd:

tar --help | Select-String zstd

Install

  1. Download CompressTarZstd.ps1.

  2. Open PowerShell in the folder containing it and run:

    .\CompressTarZstd.ps1

    If execution policy blocks it:

    powershell -ExecutionPolicy Bypass -File .\CompressTarZstd.ps1
  3. Right-click any folder in Explorer → Compress to tar.zst.

    On Windows 11, the entry appears under Show more options (or Shift+Right-click) unless you've enabled the classic context menu.

The script can be moved or deleted after install — the right-click handler is self-contained in the registry (the payload is base64-encoded into the command).


Uninstall

.\CompressTarZstd.ps1 -u

This removes HKCU:\Software\Classes\Directory\shell\CompressTarZstd. Nothing else is touched.


How it works

The installer registers a single registry key:

HKCU\Software\Classes\Directory\shell\CompressTarZstd
    (Default) = "Compress to tar.zst"
    Icon      = "shell32.dll,45"
    \command
        (Default) = cmd.exe /c set "CTZ_PATH=%1" && powershell.exe ...

The selected folder path is passed via the CTZ_PATH environment variable instead of as a PowerShell argument. This sidesteps PowerShell's argument parser entirely, which is the source of most "works for me / breaks on weird paths" pain in shell-extension scripts.

The compression payload then:

  1. Strips wrapping quotes and trailing backslashes from CTZ_PATH.
  2. Splits parent / leaf using [System.IO.Path] (avoids a PS 5.1 parameter-set bug).
  3. cds into the folder and runs tar.exe -a -cf <leaf>.tar.zst ..
  4. Writes the archive next to the source folder.

Resulting archive structure:

$ tar -tf stuff.tar.zst
./
./data.txt
./doxx.pdf
./eu-ai.txt

Logging

  • Location: %TEMP%\CompressTarZstd.log
  • Rotated at 1 MB; one previous copy kept as CompressTarZstd.log.1.
  • Deleted on success so a healthy system has no log at all.
  • If something fails, the log persists for inspection and the PowerShell window stays open for 5 seconds.

To inspect after a failure:

Get-Content $env:TEMP\CompressTarZstd.log

Limitations

  • Folders only. The handler is registered on Directory, not on individual files. Right-click a parent folder if you want to archive a single file.
  • No compression-level option. tar -a uses zstd defaults. If you want to tune it, replace the tar invocation with something like:
    & tar.exe --use-compress-program="zstd -19" -cf "$leaf.tar.zst" .
    (requires a standalone zstd.exe in PATH).
  • No progress UI. It runs hidden. For huge folders, watch the archive file size grow in Explorer.
  • Per-user only. Run from each user account that needs the entry, or adapt to HKLM if you want a machine-wide install (requires admin).

Troubleshooting

Nothing happens when I click the menu entry. Check %TEMP%\CompressTarZstd.log. If it doesn't exist, the registry entry probably isn't installed for the current user — re-run the installer.

tar.exe not found. You're on a Windows version older than 1803, or System32 isn't in PATH. Update Windows.

Parameter set cannot be resolved using the specified named parameters. This was a PS 5.1 bug in earlier versions of this script — make sure you're using the current release.

Archive contains foldername/ as the top-level entry. You're using an older version. The current script archives . from inside the folder so entries start with ./.


License

CC0 - See LICENSE.


Acknowledgements

  • tar.exe on Windows is libarchive, which has supported zstd for years.
  • Thanks to PowerShell 5.1 for being the reason this script needs [System.IO.Path] instead of Split-Path.

About

Add a menu option to compress a directory as .tar.zst in Windows File Manager

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors