Files
LogSeqDB/pages/Scripts/Powershell - delete mepty dirs.sync-conflict-20250817-085631-UULL5XD.md
2025-12-11 06:26:12 -08:00

1.1 KiB

title, updated, created, latitude, longitude, altitude
title updated created latitude longitude altitude
Poweshell - delete mepty dirs 2022-01-30 16:39:35Z 2022-01-30 16:38:59Z 40.78200000 -73.99530000 0.0000

- Set to true to test the script
  $whatIf = $false
- Remove hidden files, like thumbs.db
  $removeHiddenFiles = $true
- Get hidden files or not. Depending on removeHiddenFiles setting
  $getHiddelFiles = !$removeHiddenFiles
- Remove empty directories locally
  Function Delete-EmptyFolder($path)
  {
- Go through each subfolder, 
    Foreach ($subFolder in Get-ChildItem -Force -Literal $path -Directory) 
    {
- Call the function recursively
        Delete-EmptyFolder -path $subFolder.FullName
    }
- Get all child items
    $subItems = Get-ChildItem -Force:$getHiddelFiles -LiteralPath $path
- If there are no items, then we can delete the folder
- Exluce folder: If (($subItems -eq $null) -and (-Not($path.contains("DfsrPrivate")))) 
    If ($subItems -eq $null) 
    {
        Write-Host "Removing empty folder '${path}'"
        Remove-Item -Force -Recurse:$removeHiddenFiles -LiteralPath $Path -WhatIf:$whatIf
    }
  }
- Run the script
  Delete-EmptyFolder -path "G:\Old\"```