栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python脚本017:将多文件下的文件放在同一文件夹下

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python脚本017:将多文件下的文件放在同一文件夹下

# 导入对路径操作的库
import sys
import os
from IPython import embed
import shutil
import glob
import os, random, shutil

def makesDir(filepath): #判断如果文件不存在,则创建
    if not os.path.exists(filepath):
        os.makedirs(filepath)


def moveFile_q(fileDir, tarDir):
    pathDir = os.listdir(fileDir)  # 取图片的原始路径
    for name in pathDir:
        shutil.copy(os.path.join(fileDir,name) , os.path.join(tarDir,name))


if __name__ == '__main__':
    gallery_path = '/home/jy/xl/workstation/Datasets/Car/Nighttime_Vehicle_ReID/gallery'  # 设置创建后文件夹存放的位置
    test_temp_path = '/home/jy/xl/workstation/Datasets/Car/Nighttime_Vehicle_ReID/Gallery'  #根目录,下面有很多子文件夹

    makesDir(gallery_path)
    img_names = os.listdir(test_temp_path)

    for img_name in img_names:
        img_name_path = os.path.join(test_temp_path,img_name)
        moveFile_q(img_name_path, gallery_path)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/618316.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号