Skip to content

Instantly share code, notes, and snippets.

@s-h-a-d-o-w
Last active October 19, 2025 11:36
Show Gist options
  • Save s-h-a-d-o-w/395bcf40e018afafd2f39b27b5f33a79 to your computer and use it in GitHub Desktop.
Save s-h-a-d-o-w/395bcf40e018afafd2f39b27b5f33a79 to your computer and use it in GitHub Desktop.
The fastest way to copy a directory that I've found on Windows. Usage: "powercopy <source> <target>" - leaf directory in source will be created in target
param(
[Parameter(Mandatory=$true)]
[string]$source,
[Parameter(Mandatory=$true)]
[string]$target
)
$folderName = Split-Path $source -Leaf
$targetPath = Join-Path $target $folderName
# Create target directory if it doesn't exist
New-Item -ItemType Directory -Force -Path $targetPath | Out-Null
tar -cf - -C $source . | tar -xf - -C $targetPath
Write-Host "Copied $source to $targetPath" -ForegroundColor Green
@s-h-a-d-o-w
Copy link
Author

Based on the following benchmark where I copied the standalone build of a complex next.js app:

tar -cf - -C "source" . | tar -xf - -C "target"
Execution Time: 3.34 seconds

xcopy /e /y /q source target
Execution Time: 5.40 seconds

robocopy source target /E /MT:16 /NFL /NDL /NJH /NJS /NC /NS /NP
Execution Time: 8.58 seconds

esbuild (using copy plugin)
Execution Time: 9.42 seconds

@s-h-a-d-o-w
Copy link
Author

YMMV. Widely. Just did a benchmark with arbitrary files and got:

tar -cf - -C "source" . | tar -xf - -C "target"
Execution Time: 83.88 seconds

xcopy /e /y /q source target
Execution Time: 4.45 seconds

robocopy source target /E /MT:16 /NFL /NDL /NJH /NJS /NC /NS /NP
Execution Time: 1.3 seconds

On another machine, this even ran out of memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment