matlab批量修改文件名

描述

使用matlab,批量修改某个文件夹下的全部文件名

代码

下面的例子,是修改了某个文件夹下的全部jpg图片名,修改后的新名称是原名称的一部分

%% 批量修改图片名称
close all;
clear all;
clc
path_origin='/home/chen/CodeBase/matlab_try/front/';   % 原路径
path_new='/home/chen/CodeBase/matlab_try/front_rename/';      % 新路径,需提前创建
img_path_list=dir(strcat(path_origin,'*.jpg'));   %提取.jpg图片
img_num=length(img_path_list);        % 统计综述
for j=1:img_num
    img_name_old=img_path_list(j).name;               % 原图片名  
    sub = img_name_old(8:27);
    img_name_new=strcat(sub,'.jpg');    % 新图片名
    image=imread(strcat(path_origin,img_name_old));   % 读取
    imwrite(image,strcat(path_new,img_name_new));     % 重命名
end

猜你喜欢

转载自blog.csdn.net/weixin_42156097/article/details/128183007
今日推荐