In today's article, we will learn about one aspect of directories in python. First, in this article, we will learn about the knowledge of deleting directories in python. When you delete a directorypythonAlso the files in the directory will be deleted.
rmdir() methodmethod
rmdir() method deletes the directory, directory name Passed as parameters.
Before deleting this directory, all its contents should be cleared first.
Syntax:
os.rmdir('dirname')
Example:
The following is an example of deleting the "/tmp/test" directory. The fully qualified name of the directory must be given, otherwise the directory will be searched under the current directory.
# !/usr/bin/python # -*- coding: UTF-8 -*- import os # 删除”/tmp/test”目录 os.rmdir("/tmp/test")
The above is all the knowledge about how to delete directories in python directories in this article. I hope what I said and the examples I gave can be helpful to you.
For more related knowledge, please visit the Python tutorial column on the php Chinese website.
The above is the detailed content of How to delete python directory? Will the files in the directory also be deleted along with the directory?. For more information, please follow other related articles on the PHP Chinese website!