From ab3fbffccff242976d958382bcc6fd4f6b5f98a1 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Thu, 22 Jun 2023 02:27:27 +0100 Subject: [PATCH] fix folder deletion --- mover.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mover.ps1 b/mover.ps1 index 5208fa2..0031cb5 100644 --- a/mover.ps1 +++ b/mover.ps1 @@ -32,9 +32,10 @@ foreach ($file in $files) { Move-Item -Path $file.FullName -Destination $dest -Force Write-Host "Moved $file" - # Remove the source folder if it is empty - if (!(Get-ChildItem -Path $from -File -Recurse)) { - Remove-Item -Path $from -Force - Write-Host "Removed the folder $from, it is empty" + # Remove the folder the video was in if it is empty, and is not the source folder + $folder = Split-Path $file.FullName -Parent + if ($folder -ne $from -and (Get-ChildItem -Path $folder -File).Count -eq 0) { + Remove-Item -Path $folder -Force + Write-Host "Removed $folder" } } \ No newline at end of file