I need to rename bulk files in windows by adding some text in present files name and retaining other part as it is.

1 次查看(过去 30 天)
Passanger_last_ordercut_X
Passanger_last_ordercut_Y
Passanger_last_ordercut_Z
Passanger_Middle_ordercut_X
Passanger_Middle_ordercut_Y
Passanger_Middle_ordercut_Z
should be renamed to
Passanger_last_ordercut_X_AC
Passanger_last_ordercut_Y_AC
Passanger_last_ordercut_Z_AC
Passanger_Middle_ordercut_X_AC
Passanger_Middle_ordercut_Y_AC
Passanger_Middle_ordercut_Z_AC
I need matlab to import name of files present in given path, rename accordingly and save those files with new name. As in Passanger_last_ordercut_X.cur becomes Passanger_last_ordercut_X_AC.cur

采纳的回答

Walter Roberson
Walter Roberson 2016-10-31
dinfo = [dir('*_X.cur'); dir('*_Y.cur'); dir('*_Z.cur')];
for K = 1 : length(dinfo)
oldname = dinfo(K).name;
[folder, basename, ext] = fileparts(oldname);
newname = fullfile(folder, [basename '_AC' ext]);
movefile(oldname, newname);
end

更多回答(1 个)

KSSV
KSSV 2016-10-31
编辑:KSSV 2016-10-31
clc; clear all ;
str1 = 'Passanger_last_ordercut_X Passanger_last_ordercut_Y Passanger_last_ordercut_Z Passanger_Middle_ordercut_X Passanger_Middle_ordercut_Y Passanger_Middle_ordercut_Z' ;
rep0 = [{'_X'} {'_Y'} {'_Z'}] ; % replace these characters
rep1 = [{'_X_AC'} {'_Y_AC'} {'_Z_AC'}] ; % with these
for i = 1:length(rep0)
str1 = strrep(str1, rep0{i}, rep1{i}) ;
end
  5 个评论
Image Analyst
Image Analyst 2016-11-1
Aditya, since you asked, you must not know about the FAQ. Both answers are essentially in the FAQ, with the addition of a movefile() in the middle of the loop to do the renaming. Here is the FAQ (there's other good stuff in there too so you should look at it all): http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by