Copiez le nom de fichier spécifié ou le contenu du dossier dans le fichier spécifié --- par exemple : json

Ce qui suit consiste à copier le fichier json sous le dossier du dossier 0 vers un autre répertoire de fichiers json 0. Il y a plusieurs fichiers json ci-dessous qui peuvent être modifiés, dans le code.

import os
import shutil

path = r'C:\Users\Administrator\Desktop\project\fire_dataset_7_0\0'
new_path = r'C:\Users\Administrator\Desktop\project\fire_dataset_7_0\0_json'
filelist = os.listdir(path)
i = 1

for item in filelist:
    if item.endswith('json') or item.endswith('json') or item.endswith('json') or item.endswith('json'):
        src = os.path.join(os.path.abspath(path), item)
        dst = os.path.join(os.path.abspath(new_path),item)
        # new_name = os.path.join(os.path.abspath(new_path),''+str(i)+'.bmp')

        new_name = os.path.join(os.path.abspath(new_path), '' + str(i)+'.json')
       #复制图像
        shutil.copy(src,dst)
       #重命名---把下面两行注释了就不会更改图片的名字。。。
        os.rename(dst, new_name)
        i += 1

        print(src)
        print(new_name)


Je suppose que tu aimes

Origine blog.csdn.net/qq_44666320/article/details/126675544
conseillé
Classement