根据图片名的关键词进行分类

import os
import imghdr
import shutil
import stat


def move_classification(file_path):
    arr_files = file_path.split("_")
    # print(arr_files[1])
    # print(images_path)
    folder_path = os.path.join("汽车_classification", arr_files[1])
    if not os.path.exists(folder_path):
        os.makedirs(folder_path)
    print(file_path, folder_path)
    shutil.move(file_path, folder_path)


if __name__ == '__main__':
    images_path = r"./汽车/"
    for root, dirs, files in os.walk(images_path):
        for file in files:
            files_path = os.path.join(root, file)
            # print(files_path)
            move_classification(files_path)

你可能感兴趣的:(python数据处理)