$base = 'F:\Workin In Progress\DESINEURON\GITLAB\Velocity-OS\webos\src'

$doubleDirs = 'shared\hooks\hooks','shared\lib\lib','shared\ui\ui','shared\types\types','store\store'

foreach ($dir in $doubleDirs) {
  $srcDir = Join-Path $base $dir
  $dstDir = Split-Path $srcDir -Parent
  if (Test-Path $srcDir) {
    Write-Host "Flattening: $srcDir"
    Get-ChildItem -Path $srcDir -File | ForEach-Object {
      $target = Join-Path $dstDir $_.Name
      if (-not (Test-Path $target)) {
        Move-Item $_.FullName $dstDir -Force
        Write-Host "  Moved: $($_.Name)"
      } else {
        Write-Host "  Skip (already exists): $($_.Name)"
      }
    }
    if ((Get-ChildItem $srcDir -Force | Measure-Object).Count -eq 0) {
      Remove-Item $srcDir -Force
      Write-Host "  Removed empty dir."
    }
  } else {
    Write-Host "Not found (ok): $srcDir"
  }
}
Write-Host "All done."
