Skip to content

Instantly share code, notes, and snippets.

Created February 24, 2018 00:13
Show Gist options
  • Save anonymous/bdcc59e8b72a7ae60ce5a2340093ca86 to your computer and use it in GitHub Desktop.
Save anonymous/bdcc59e8b72a7ae60ce5a2340093ca86 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Feb 24, 2018.
    26 changes: 26 additions & 0 deletions rmblanks.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #-------------------------------------------------------------
    # rmblanks.py
    # Deletes all empty folders under a given path.
    # http://metinsaylan.com
    #-------------------------------------------------------------

    # Usage: rmblanks.py "E:/Test"

    import sys, os

    if len(sys.argv) == 1:
    # Print usage
    print("Usage: rmblanks.py \"E:/TestFolder\"")
    else:
    for root, dirs, files in os.walk(sys.argv[1], topdown=False):
    for name in dirs:
    try:
    if len(os.listdir( os.path.join(root, name) )) == 0: #check whether the directory is empty
    print( "Deleting", os.path.join(root, name) )
    try:
    os.rmdir( os.path.join(root, name) )
    except:
    print( "FAILED :", os.path.join(root, name) )
    pass
    except:
    pass