简体   繁体   中英

how in python remove all folder inside path

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

import os
import shutil

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM