how to change file names in matlab

Assuming we have some files in a fold named 'photo', some file names are ended with '.gif', some of them are not. now our goal is to add '.gif' suffix to all the files except the '.gif' files they were before.


 

pics = dir('photo');%list all the files in folder photo
name = extractfield(pics, 'name');% extract name fields into a cell array
index = ~ismember(name,[ {'.'},{'..'}]);%exclude current directory and parent directory
name = name(index);

gif = regexp(name, '.gif$');%find out the original gif files
index_nongif = cellfun(@isempty, gif);% filter out gif files
name = name(index_nongif);


before_name = cellfun(@strcat, repmat({'photo\'},size(name)), name, 'UniformOutput', 0);% add photo prefix
after_name = cellfun(@strcat, before_name, repmat({'.gif'},size(name)), 'UniformOutput', 0);% add .gif suffix


cellfun(@movefile, before_name, after_name)% change file names

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/seamanj/article/details/54003317
个人分类: MATLAB
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

how to change file names in matlab

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭