【问题标题】:How to rename the pictures after unzip file with the name based on unzip file's name with pythonpython - 如何使用基于解压缩文件名称的名称解压缩文件后重命名图片
【发布时间】:2021-02-14 20:52:51
【问题描述】:

我在文件夹 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)

【问题讨论】:

    标签: python rename unzip zipfile file-rename


    【解决方案1】:

    你可以这样做,别忘了把扩展名放在文件名后面

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-16
      • 2013-12-29
      • 2020-12-12
      • 1970-01-01
      相关资源
      最近更新 更多