Deleting empty folders


  1. Posts : 116
    10pro 20H2 19042.1237
       #1

    Deleting empty folders


    Following on from this thread ...
    Can't find empty folders using Windows Explorer search function
    And specifically this post ...
    You can use PowerShell. Assumed you're in the top-level folder you want to search, the command is:
    Code:
    gci -recurse -Directory | ?{(gci $_.Fullname).count -eq 0}
    This works as described and lists the empty directories/folders.

    How can I change that powershell script to then delete those folders ?

    Have had little or limited success with explorer not finding empties and "RED" Remove Empty Directories" from jonasjohn.de
    And XYplorer free no longer exists or there are 'issues'.

    20H2 pro up-to-date on w11 capable laptop.
      My Computers

  2.   My Computer


  3. Posts : 42,992
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #3

    Has XYplorer free been discontinued?

    A simple search would give you:

    XYplorer - XYplorerFree
      My Computers


  4. Posts : 116
    10pro 20H2 19042.1237
    Thread Starter
       #4

    Thank you Paul Black.
    Just read through two of those stack threads and now realise how little I undestand of scripting.
    As there are disagreements within these threads and all is above my altitude I do not know which version to try.
    I "think" that this is the most favoured ?
    # A script block (anonymous function) that will remove empty folders
    # under a root folder, using tail-recursion to ensure that it only
    # walks the folder tree once. -Force is used to be able to process
    # hidden files/folders as well.
    $tailRecursion = {
    param(
    $Path
    )
    foreach ($childDirectory in Get-ChildItem -Force -LiteralPath $Path -Directory) {
    & $tailRecursion -Path $childDirectory.FullName
    }
    $currentChildren = Get-ChildItem -Force -LiteralPath $Path
    $isEmpty = $currentChildren -eq $null
    if ($isEmpty) {
    Write-Verbose "Removing empty folder at path '${Path}'." -Verbose
    Remove-Item -Force -LiteralPath $Path
    }
    }
    And this one is challenged within the thread ..
    gci $Path -force -recurse|
    Where{$_.psiscontainer -and (gci $_.FullName -force -recurse|?{!$_.psiscontainer}).count -eq 0}|
    Remove-Item -Recurse -force
    - - - Updated - - -

    Thank you dalchina

    This works.
    Free version seems to be perfectly usable and does show folder sizes very easily.
    And explains why I have been unsuccessful with all the other methods.
    Turns out there are old icon files from a previous incarnation of this directory structure.
    These were not deleted by my duplicate finding runs (Auslogics ... but cannot remember if I had the file size limits set correctly).

    The powershell was looking a bit intimidating ... especially the warning about C: !
    Now back to hunt down any more of those icons.
    Paul

    - - - Updated - - -

    Success .. but method might be useful to others in same boat.

    Windows file explorer could not find these icon files ... using *.* OR *.ico* OR *ico*
    But via XYplorer ...
    ... each opened as multipage icon files with seven versions of each folder ico (Foderico by Shedko).

    So XYplorer was able to find them all.
    So have bulk found selected deleted and checked the software thing is uninstalled.

    Now going to revert to a years old method of creating my own icons in a folder and using them (prefer visual methods to text methods for finding things).

    So marking solved .. but still surprised that an old (2016) bit of third party software is SOOO much better than current w10pro at finding things ...
    Over and out
    Paul
      My Computers


  5. Posts : 42,992
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #5

    Notice that XYplorer readily allows folder size to be displayed: Windows doesn't.

    File explorer search syntax does not support searching for folder size- only file size.

    An O/S provides a platform. Applications enhance what can be done and add value.
    If Windows did everything... and did it all well - a lot of people would be out of business!
      My Computers


  6. Posts : 2,143
    Windows 11 Pro (latest update ... forever anal)
       #6

    RED aka Remove Empty Directories
    Remove Empty Directories (aka RED)
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 08:48.
Find Us




Windows 10 Forums