Skip to content

Instantly share code, notes, and snippets.

@cpereira7
Created August 10, 2025 18:35
Show Gist options
  • Select an option

  • Save cpereira7/4baafb9245882d906a3dddca4922d170 to your computer and use it in GitHub Desktop.

Select an option

Save cpereira7/4baafb9245882d906a3dddca4922d170 to your computer and use it in GitHub Desktop.
param (
[Parameter(Mandatory=$true)]
[string]$source,
[Parameter(Mandatory=$true)]
[string]$destination
)
# Get all files to be copied
$files = Get-ChildItem -Path $source -Recurse -File
$totalFiles = $files.Count
$copiedFiles = 0
foreach ($file in $files) {
$sourceFile = $file.FullName
$destFile = $file.FullName.Replace($source, $destination)
# Ensure the destination directory exists
$destDir = [System.IO.Path]::GetDirectoryName($destFile)
if (!(Test-Path -Path $destDir)) {
New-Item -ItemType Directory -Path $destDir | Out-Null
}
# Copy the file
Copy-Item -Path $sourceFile -Destination $destFile
# Update progress
$copiedFiles++
$progress = ($copiedFiles / $totalFiles) * 100
Write-Progress -Activity "Copying Files" -Status "$progress% Complete" -PercentComplete $progress -CurrentOperation $sourceFile
}
Write-Progress -Activity "Copying Files" -Completed
Write-Output "Backup completed successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment