Code Formatting Changes - 'Copy-Files' Private Function

This commit is contained in:
Mr.k 2024-07-26 23:16:27 +03:00
parent dbf3aa2d5c
commit b7b64170d5
No known key found for this signature in database

View File

@ -21,27 +21,22 @@ function Copy-Files {
$files = Get-ChildItem -Path $path -Recurse:$recurse $files = Get-ChildItem -Path $path -Recurse:$recurse
Write-Host "Copy $($files.Count)(s) from $path to $destination" Write-Host "Copy $($files.Count)(s) from $path to $destination"
foreach($file in $files) foreach ($file in $files) {
{
$status = "Copy files {0} on {1}: {2}" -f $counter, $files.Count, $file.Name $status = "Copy files {0} on {1}: {2}" -f $counter, $files.Count, $file.Name
Write-Progress -Activity "Copy Windows files" -Status $status -PercentComplete ($counter++/$files.count*100) Write-Progress -Activity "Copy Windows files" -Status $status -PercentComplete ($counter++/$files.count*100)
$restpath = $file.FullName -Replace $path, '' $restpath = $file.FullName -Replace $path, ''
if($file.PSIsContainer -eq $true) if ($file.PSIsContainer -eq $true) {
{
Write-Debug "Creating $($destination + $restpath)" Write-Debug "Creating $($destination + $restpath)"
New-Item ($destination+$restpath) -Force:$force -Type Directory -ErrorAction SilentlyContinue New-Item ($destination+$restpath) -Force:$force -Type Directory -ErrorAction SilentlyContinue
} } else {
else
{
Write-Debug "Copy from $($file.FullName) to $($destination+$restpath)" Write-Debug "Copy from $($file.FullName) to $($destination+$restpath)"
Copy-Item $file.FullName ($destination+$restpath) -ErrorAction SilentlyContinue -Force:$force Copy-Item $file.FullName ($destination+$restpath) -ErrorAction SilentlyContinue -Force:$force
Set-ItemProperty -Path ($destination+$restpath) -Name IsReadOnly -Value $false Set-ItemProperty -Path ($destination+$restpath) -Name IsReadOnly -Value $false
} }
} }
Write-Progress -Activity "Copy Windows files" -Status "Ready" -Completed Write-Progress -Activity "Copy Windows files" -Status "Ready" -Completed
} } catch {
Catch{
Write-Warning "Unable to Copy all the files due to unhandled exception" Write-Warning "Unable to Copy all the files due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace Write-Warning $psitem.Exception.StackTrace
} }