0

How can I list all folders of a directory in Python and remove them ?

for root, dirs, files in os.walk(r'/home/m110/public_html/ts/'):
    print(root)
    print(dirs)
    print(files)

i run this code in Centos7 but i just need list folder for delete times

  • 1
    Does this answer your question? [Deleting folders in python recursively](https://stackoverflow.com/questions/13118029/deleting-folders-in-python-recursively) – abc Feb 15 '20 at 11:55

1 Answers1

1
import os
import shutil

dirs= next(os.walk(r'/home/m110/public_html/ts/'))[1]
for name in dirs:
    print name
    shutil.rmtree(name)
sirmagid
  • 1,090
  • 1
  • 16
  • 23