本文共 867 字,大约阅读时间需要 2 分钟。
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 photoname = extractfield(pics, 'name');% extract name fields into a cell arrayindex = ~ismember(name,[ {'.'},{'..'}]);%exclude current directory and parent directoryname = name(index);gif = regexp(name, '.gif$');%find out the original gif filesindex_nongif = cellfun(@isempty, gif);% filter out gif filesname = name(index_nongif);before_name = cellfun(@strcat, repmat({'photo\'},size(name)), name, 'UniformOutput', 0);% add photo prefixafter_name = cellfun(@strcat, before_name, repmat({'.gif'},size(name)), 'UniformOutput', 0);% add .gif suffixcellfun(@movefile, before_name, after_name)% change file names
转载地址:http://jpxdi.baihongyu.com/