Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Cách xóa thư mục bằng Python?


Muốn xóa thư mục rỗng, gọi rmdir trong module os.

Ví dụ

>>> import os
>>> os.rmdir('my_folder')

Muốn xóa thư mục chứa file, xóa thư mục như sau:

>>> import shutil
>>> shutil.rmtree('my_folder')