Matlab 中的copyfile函数使用小记

       因为最近使用labelImg软件标注训练图片,我把标记好的图片和标注文件放置在一个文件夹下,由于有多批次图片标注,每标注一批放在一个文件夹下,最终放置的文件夹如下:

现在我需要把这些文件夹下的图片和标注文件集中到两个文件ImSet(用于放置所有的标注图片),AnotSet(用于放置所有的标注文件)

为此我写了一个Matlab程序,主要函数是copyfile,好了现在直接上Matlab程序吧

%2018/09/07 by DQ
clc;
clear;
close all;
DisperalMainFolder='H:\WorkFile\SecondPeroidAnotBackup';
ConcentrateFolder='C:\Users\Administrator\Desktop\SecondPeroidUnifySet';
OldFileSet=dir(ConcentrateFolder);
OldFileSet(1:2)=[];
if ~isempty(OldFileSet)
   disp('the folder exists other files');
   return
end
ImFolderPath=fullfile(ConcentrateFolder,'ImSet');
if ~exist(ImFolderPath,'dir')
    mkdir(ImFolderPath);
end
AnotFolderPath=fullfile(ConcentrateFolder,'AnotSet');
if ~exist(AnotFolderPath,'dir')
    mkdir(AnotFolderPath);
end

FolderSet=dir(DisperalMainFolder);
FolderNum=length(FolderSet);
for i=3:FolderNum
    FolderName=FolderSet(i).name;
    FolderPath=fullfile(DisperalMainFolder,FolderName);
    XmlFileSet=dir(strcat(FolderPath,'\*.xml'));
    XmlFileNum=length(XmlFileSet);
    fprintf('%s XmlFileNum=%d\n',FolderName,XmlFileNum);
    %%%%%%%start%%%%%%%%%%
    for k=1:XmlFileNum
        XmlFileName=XmlFileSet(k).name;
        XmlFilePath=fullfile(FolderPath,XmlFileName);
        copyfile(XmlFilePath,AnotFolderPath);%复制标注文件到指定的文件夹
        ImName=strcat(XmlFileName(1:end-4),'.jpg');
        ImPath=fullfile(FolderPath,ImName);
        copyfile(ImPath,ImFolderPath);%复制图片到指定的文件夹
    end
    %%%%%%%end%%%%%%%%%%
%     %%上述start和end之间的程序有一种更简洁的方式
%     XmlFileS=strcat(FolderPath,'\*.xml');%复制文件夹FolderPath下所有后缀名为.xml的文件
%     copyfile(XmlFileS,AnotFolderPath);
%     ImFileS=strcat(FolderPath,'\*.jpg');%复制文件夹FolderPath下所有后缀名为.jpg的文件
%     copyfile(ImFileS,ImFolderPath);
end

 

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值