开发者

deletion of folders

开发者 https://www.devze.com 2022-12-25 20:16 出处:网络
how can i delete a folde开发者_运维百科r using python script?and what are the return values??If you want to delete a folder that\'s empty use os.rmdir:

how can i delete a folde开发者_运维百科r using python script?and what are the return values??


If you want to delete a folder that's empty use os.rmdir:

import os
os.rmdir('/mypath')

If you want to delete a folder that's not empty use shutil.rmtree:

import shutil  
shutil.rmtree('/mypath')


you can use os.rmdir() to remove a directory. To remove a directory tree recursively, you can use shutil.rmtree. If you know that you already have empty directory nodes, you can also check out os.removedirs()

0

精彩评论

暂无评论...
验证码 换一张
取 消