Skip to content

Remove files and directories

For removing files and directories, there are 3 commands:

To remove a single file, use os.remove():

import os

To remove an empty directory, use os.rmdir():

import os

To remove a directory and all its contents (in other words, delete recursively), use shutil.rmtree():

import shutil


Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.