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

Cách xóa thư mục Python hiệu quả?


Nếu muốn xóa thư mục rỗng, bạn gọi hàm rmdir trong module os.

Ví dụ

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

Nếu muốn xóa thư mục chứa file, bạn xóa thư mục như sau:

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