关闭

how to change file names in matlab

146人阅读 评论(0) 收藏 举报
分类:

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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:446719次
    • 积分:10522
    • 等级:
    • 排名:第1736名
    • 原创:604篇
    • 转载:96篇
    • 译文:0篇
    • 评论:96条
    最新评论