From ec22def28215415614ec1f8024edf59f05292422 Mon Sep 17 00:00:00 2001 From: NilsGrunwald Date: Sat, 6 Nov 2021 14:03:55 +0100 Subject: [PATCH] Bugfix --- Backup2ExternalHD.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Backup2ExternalHD.ps1 b/Backup2ExternalHD.ps1 index 19c67e5..a353af4 100644 --- a/Backup2ExternalHD.ps1 +++ b/Backup2ExternalHD.ps1 @@ -26,6 +26,7 @@ function Backup-Data($SourcePath,$BackupPath){ $BackupDrive = $BackupPath -replace(':.*','') $move = $true foreach($f in $sources){ + $Source = $f.FullName if ($f -eq $sources[$sources.Length-1]){ Write-Host("Copying: $f") $move = $false @@ -33,15 +34,16 @@ function Backup-Data($SourcePath,$BackupPath){ Write-Host("Moving: $f") $move = $true } - $foldersize = (Get-ChildItem -path $f.FullName -Recurse | Measure-Object -Property Length -sum).Sum / 1Gb + $foldersize = (Get-ChildItem -path $Source -Recurse | Measure-Object -Property Length -sum).Sum / 1Gb $free = (Get-PSDrive -Name $BackupDrive).Free / 1Gb Write-Host(" Backup-Data-Size: $foldersize (free: $free)") if ($foldersize -lt $free){ - $Destination = $BackupPath+"\"+$f + $Destination = $BackupPath+"\"+$f + Write-Host(" Source-Path: $Source") Write-Host(" Target-Path: $Destination") Copy-Dir -Source $SourcePath -Destination $Destination if ($move){ - Remove-Item -Recurse -Force $SourcePath + Remove-Item -Recurse -Force $Source } } else { Write-Host("ERROR: Not enough free space on Backup-Drive!")