HOWTO · PowerShell

How to Copy Folder With Subfolders in PowerShell

This tutorial teaches you how to copy a folder with subfolders using PowerShell.

On this page

This guide shows how to copy a folder with PowerShell, including its files and nested folders, and how to check the destination. Copy-Item is useful when you need a repeatable command for copying folders to one or more locations.

Copy a Folder in PowerShell

The destination layout depends on whether you copy the source folder itself or its contents. Copy-Item accepts a source path through -Path and a target location through -Destination. Use -Recurse when the copy must include files and subfolders. The examples below use temporary paths so you can run them without relying on an existing C:\test_folder1 directory.

Copy a Folder and Its Contents with Copy-Item

To copy a folder together with its contents, use Copy-Item with -Recurse. When the destination directory already exists, this command places the source directory inside it. For example, copying C:\Source\Reports to C:\Archive produces C:\Archive\Reports, including the files and subfolders under Reports.

Run this example to create a source folder, copy it, and count the copied files:

$root = Join-Path ([System.IO.Path]::GetTempPath()) ("copy-item-demo-" + [guid]::NewGuid().ToString("N"))
$source = Join-Path $root 'Source'
$destination = Join-Path $root 'Destination'
$nested = Join-Path $source 'Monthly'
New-Item -ItemType Directory -Path $nested -Force | Out-Null
New-Item -ItemType Directory -Path $destination -Force | Out-Null
Set-Content -Path (Join-Path $source 'summary.txt') -Value 'Annual summary'
Set-Content -Path (Join-Path $nested 'january.txt') -Value 'January report'
Copy-Item -Path $source -Destination $destination -Recurse -PassThru | Out-Null
$copiedFolder = Join-Path $destination (Split-Path $source -Leaf)
$files = Get-ChildItem -Path $copiedFolder -Recurse -File
Write-Output "Files copied: $($files.Count)"
Files copied: 2

The supplied run completed successfully with exit code 0 and reported Files copied: 2. The optional -PassThru parameter returns an object for the copied item; it is sent to Out-Null above because the final line reports a simple file count instead. Remove Out-Null if you want to inspect that returned object in your own session.

Without -Recurse, Copy-Item copies a directory item but does not copy the directory’s contents. For example, Copy-Item -Path 'C:\Source\Reports' -Destination 'C:\Archive' creates the Reports directory at the destination without its files. Add -Recurse when those contents are needed.

Copy Folder Contents Without the Parent Folder

Sometimes the destination should receive the source folder’s contents directly, without an extra parent directory. Put a wildcard at the end of the source path and keep -Recurse, as in Copy-Item -Path 'C:\Source\Reports\*' -Destination 'C:\Archive' -Recurse. The files and subfolders inside Reports are copied into Archive; the Reports directory itself is not added as another level. Check that the destination is the intended location before running the command, especially when repeating it for several source folders. A wildcard can match more than one item, so review the source path before using it in a batch operation. If a folder name contains wildcard characters that should be treated literally, use the -LiteralPath parameter instead of -Path; -LiteralPath does not interpret wildcard characters.

Verify the Copied Files and Folders

Use Get-ChildItem to inspect the destination. For the recursive example, Get-ChildItem -Path $copiedFolder -Recurse lists the copied folder’s files and subfolders. To inspect only the immediate contents, omit -Recurse; to count files recursively, use Get-ChildItem -Path $copiedFolder -Recurse -File | Measure-Object. Compare the listed names and folder structure with the source so you can confirm that the intended items arrived. For the wildcard form, inspect the destination itself: its contents should appear directly there, without the source folder as a parent. These checks let you distinguish a successful copy from a command that copied only the directory entry or used a different destination layout.