使用Python的os模块可以删除目录。可以使用os.rmdir()函数删除空目录,或者使用shutil模块的shutil.rmtree()函数删除非空目录。

删除空目录的示例代码:

import os

os.rmdir('path/to/directory')

删除非空目录的示例代码:

import shutil

shutil.rmtree('path/to/directory')

在这些代码中,'path/to/directory'应替换为要删除的目录的路径。请注意,删除目录是不可逆的操作,请谨慎使用。

python删除目录

原文地址: http://www.cveoy.top/t/topic/ebj5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录