How do I find all the empty folders and delete them.

Anonymous
2011-04-03T17:52:58+00:00

My music has a bunch of folders that are empty but it will take forever to look at every single one.  I want to search by size or someway that will make it easier to find and delete

Windows for home | Previous Windows versions | Files, folders, and storage

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
Anonymous
2011-05-15T16:05:51+00:00

Hello !

If you do want to delete all the empty folders only ! go to Computer and at the top right click on search. Click on kind and Select folder, now click again on search and click on size, select 0 and click on search.

This should list all the empty folders

Regards

Was this answer helpful?

800+ people found this answer helpful.
0 comments No comments

55 additional answers

Sort by: Newest
  1. Anonymous
    2016-02-02T09:04:48+00:00

    The -Directory parameter was introduced in PowerShell 3.0. This command should work for older versions of PowerShell:

    dir -Recurse | where {$_.PSIsContainer -and ($_ | dir).Count -eq 0} | rmdir

    Source: Stack Overflow

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2016-01-29T09:48:23+00:00

    I tried running this in Windows 7 but got error, I then tried running it like this:

    for /f "usebackq" %d in ("dir /ad/b/s | sort /R") do rd "%d"

    only got error:The system cannot find the file specified.

    It seemed to error out on all directories with spaces even with "%d". The quote would be at the space and truncate the full directory name.

    Any help would be much appreciated. Thank You for you support!-)

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2016-01-29T03:19:52+00:00

    I did some research and was able to get this to working running in Windows 7 PowerShell using the same command with only one minor change:

    dir -D -Recurse | where {($_ | dir).Count -eq 0} | rmdir

    or to preview using:

    dir -D -Recurse | where {($_ | dir).Count -eq 0} | rmdir -WhatIf

    Thank You for your support!-)

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2016-01-29T02:25:25+00:00

    I get the following from PowerShell:

    PS Y:> dir -Directory -Recurse | where {($_ | dir).Count -eq 0} | rmdir

    Get-ChildItem : A parameter cannot be found that matches parameter name 'Directory'.

    At line:1 char:15

    • dir -Directory <<<<  -Recurse | where {($_ | dir).Count -eq 0} | rmdir

        + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException

        + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

    Please let me know what I did wrong.  Running Windows 7 Ultimate SP1.

    Thank You!-)

    Was this answer helpful?

    0 comments No comments