Home  >  Article  >  Backend Development  >  How to delete python directory? Will the files in the directory also be deleted along with the directory?

How to delete python directory? Will the files in the directory also be deleted along with the directory?

乌拉乌拉~
乌拉乌拉~Original
2018-08-17 17:54:291552browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn