python递归解压缩文件
时间: 2023-05-12 11:02:49 浏览: 305
可以使用Python的zipfile模块来解压缩文件,以下是递归解压缩文件的代码:
```python
import os
import zipfile
def unzip_file(path, dest):
with zipfile.ZipFile(path, 'r') as zip_ref:
zip_ref.extractall(dest)
for root, dirs, files in os.walk(dest):
for file in files:
if file.endswith('.zip'):
file_path = os.path.join(root, file)
unzip_file(file_path, dest)
```
其中,path是要解压缩的文件路径,dest是解压缩后的目标文件夹路径。这段代码会递归地解压缩所有嵌套的zip文件。
阅读全文
相关推荐
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044736.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20210720083447.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)