Improve error handling for file copy

This commit is contained in:
CodingWonders 2024-10-02 14:13:57 +02:00
parent 669910f792
commit b50b0be8b4

View File

@ -19,10 +19,10 @@ function Copy-Files {
try {
$files = Get-ChildItem -Path $path -Recurse:$recurse
Write-Host "Copy $($files.Count)(s) from $path to $destination"
Write-Host "Copy $($files.Count) file(s) from $path to $destination"
foreach ($file in $files) {
$status = "Copy files {0} on {1}: {2}" -f $counter, $files.Count, $file.Name
$status = "Copying file {0} of {1}: {2}" -f $counter, $files.Count, $file.Name
Write-Progress -Activity "Copy Windows files" -Status $status -PercentComplete ($counter++/$files.count*100)
$restpath = $file.FullName -Replace $path, ''
@ -37,7 +37,7 @@ function Copy-Files {
}
Write-Progress -Activity "Copy Windows files" -Status "Ready" -Completed
} catch {
Write-Warning "Unable to Copy all the files due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
Write-Warning "Unable to Copy all the files due to unhandled exception:"
Write-Warning $psitem.Exception.ToString()
}
}