Skip to content

Instantly share code, notes, and snippets.

@iqwirty
Created March 28, 2014 15:08
Show Gist options
  • Save iqwirty/9834983 to your computer and use it in GitHub Desktop.
Save iqwirty/9834983 to your computer and use it in GitHub Desktop.
Copy all files matching a pattern from one folder to another. A counter is pre-pended to ensure unique destination file names.
#
# Copy all files matching a pattern from one folder to another. A counter is pre-pended to
# ensure unique destination file names.
#
Clear-Host
$sourceFolderFullPath = "C:\SOURCE_PATH"
$destinationFolderFullPath = "C:\DESTINATION_PATH"
$filter = "FILTER*.TXT"
$count = 1
Get-ChildItem -Path $sourceFolderFullPath -Filter $filter -Recurse | `
ForEach-Object `
{
Write-Host "Copying $($_.FullName)..."
Copy-Item -Path $_.FullName `
-Destination "$destinationFolderFullPath\${count} - $_"
$count++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment