필터 지우기
필터 지우기

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
Aditya Palsule
Aditya Palsule 2016년 11월 2일
Image, thanks a lot for informing me about it. I had never checked it out.

댓글을 달려면 로그인하십시오.

카테고리

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