繁体   English   中英

如何使用python根据解压文件的名称重命名解压文件后的图片

[英]How to rename the pictures after unzip file with the name based on unzip file's name with python

我在文件夹 A 中有 zip 文件,我想解压缩它并根据 zip 文件的名称重命名解压缩文件中的图片,然后将其移动到文件夹 B。但我不知道如何重命名。 请帮忙!

我有这样的脚本:

path = r'C:\Users\A'
path_to_extract = r'C:\Users\B'
for root, dirs, files in os.walk(path):
    for file in files:
        if '.zip' in str(file):
            file_path = path + '/' + file
            zip_ref = zipfile.ZipFile(file_path, 'r') 
            zip_ref.extractall(path_to_extract)

你可以这样做,不要忘记将扩展名放在文件名后面

import os

os.rename(r'file path with old filename',r'file path with new filename')

暂无
暂无

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

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