fix folder deletion

This commit is contained in:
Lee 2023-06-22 02:27:27 +01:00
parent 0b63a079c3
commit ab3fbffccf

@ -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"
}
}