Home > Backend Development > Python Tutorial > 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?

乌拉乌拉~
Release: 2018-08-17 17:54:29
Original
1577 people have browsed it

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')
Copy after login


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")
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template