MATLAB批量读取文件夹中文件,处理后放在新的文件夹中

clc;clear all;close all
%%
% currPath = fileparts(mfilename('fullpath'));% 获得当前路径
currPath='C:\MATLAB\R2007b\toolbox\images\imdemos\html';
imagetype=char('.png');
nameall=strcat('*',imagetype);
A = dir(fullfile(currPath,nameall));
% 读取后A的格式为    
%                   name  -- filename
%                   date  -- modification date
%                   bytes -- number of bytes allocated to the file
%                   isdir -- 1 if name is a directory and 0 if not
%                   未知
A = struct2cell(A);
num = size(A);
for k =0:num(2)-1
    x(k+1) = A(5*k+1);% 找出name序列,x存储内容图片名字
end
%% 新建路径
newdir=char('ning_result');
mkdir(newdir) 
%% 读取得到mat文件
for k = 1:num(2)
    newpath = strcat(currPath,'\',x(k));
    temp = strcat(newpath,imagetype);
    image_name=char(x(k))
    im_temp=imread(char(newpath));
    newname=char(strcat(newdir,'\',image_name))
%    imwrite(im_temp,'dirName\图象.jpg','jpg');
    imwrite(im_temp,sprintf('%s%d%s',newname,k,imagetype));
%     imwrite(im_temp,[newdir,sprintf('%s%d%s','new',k,imagetype)]); 
end
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值