python shutil删除目录
时间: 2023-10-13 13:26:38 浏览: 45
你可以使用Python标准库中的shutil模块来删除目录。下面是一个示例代码:
```python
import shutil
# 删除目录
shutil.rmtree('/path/to/directory')
```
其中,`rmtree()`函数可以递归地删除目录及其所有内容。请注意,此操作是不可逆的,因此请确保你真正想要删除该目录。
相关问题
python shutil 删除文件
以下是使用shutil模块删除文件的两个示例:
示例1:删除指定目录下的文件夹及其内容
```python
import shutil
import os
location = "E:/Projects/PythonPool/"
dir = "Test"
path = os.path.join(location, dir)
shutil.rmtree(path)
```
示例2:删除指定目录下的文件夹及其内容
```python
import shutil
import os
# location
location = "E:/Projects/PythonPool/"
# directory
dir = "Test"
# path
path = os.path.join(location, dir)
# removing directory
shutil.rmtree(path)
```
python用shutil删除目录下的文件
可以使用shutil模块中的rmtree函数来删除目录下的所有文件,示例代码如下:
```python
import shutil
# 删除目录下的所有文件
shutil.rmtree('/path/to/directory')
```
注意:该函数会删除目录下的所有文件和子目录,慎用!