[Python] Remove empty folders (Python)

Discussão em 'Python' iniciado por Stack, Junho 3, 2025.

  1. Stack

    Stack Membro Participativo

    This is the folder tree:

    FOLDER\\
    \\1\\file
    \\2\\file
    \\3\\
    \\4\\file


    The script should scan (loop) for each folder in FOLDER and check if the sub-folders are empty or not. If they are, they must be deleted.

    My code, until now, is this:

    folders = ([x[0] for x in os.walk(os.path.expanduser('~\\Desktop\\FOLDER\\DIGITS\\'))])
    folders2= (folders[1:])


    This scan for folders and, using folders2 begin from the firs folder in DIGITS. In DIGITS there are numbered directories: 1,2,3,4,etc

    Now what? Tried using os.rmdir but it gives me an error, something about string. In fact, folders2 is a list, not a string, just saying...

    Continue reading...

Compartilhe esta Página