简体   繁体   English

如何根据Python中文件名的位置解压缩和重命名文件

[英]How to unzip and rename file based on position of filename in Python

I have a use case where I need to remove the last few numbers in the filename.我有一个用例,我需要删除文件名中的最后几个数字。 How do I achieve this in Python?我如何在 Python 中实现这一点?

Zip file: xyz_abc.gz
Unzipped version: xyz_abc_20180825_201808284520842.gz
Final Expected Filename: xyz_abc_20180825.gz

This has to be recursive since I have many files under the folder.这必须是递归的,因为我在文件夹下有很多文件。

要解压缩,您可以使用库“zipfile”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM