python文件整理-cornell数据集为例

python文件整理-cornell数据集为例

首先创建好几个文件夹,第一个文件夹为下载的cornell数据集
在这里插入图片描述
在这里插入图片描述

源代码:将文件复制到每一个类别的文件夹中

import os
import shutil

file_root = r"C:\Users\lenovo\Desktop\python\cornell"
image = r"C:\Users\lenovo\Desktop\python\cornell\image"
pos_label = r"C:\Users\lenovo\Desktop\python\cornell\pos_label"
neg_label = r"C:\Users\lenovo\Desktop\python\cornell\neg_label"
point_cloud = r"C:\Users\lenovo\Desktop\python\cornell\point_cloud"

root = [x[0] for x in os.walk(file_root)]
root = root[1:]

for path in root:
    for x in os.scandir(path):
        if x.name.endswith(".png"):
            needpath = '{path}/{name}'.format(path=path, name=x.name)
            shutil.copy(needpath, image)
        if x.name.endswith("pos.txt"):
            needpath = '{path}/{name}'.format(path=path, name=x.name)
            shutil.copy(needpath, pos_label)
        if x.name.endswith("neg.txt"):
            needpath = '{path}/{name}'.format(path=path, name=x.name)
            shutil.copy(needpath, neg_label)

for path in root:
    for x in os.scandir(path):
        needpath = '{path}/{name}'.format(path=path, name=x.name)
        shutil.copy(needpath, point_cloud)

参考链接:

python模块(shutil文件复制,移动)
https://blog.csdn.net/qq_37634812/article/details/79206025

©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页