Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 31 Okt. 2016
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

Weitere Antworten (1)

KSSV
KSSV am 31 Okt. 2016
Bearbeitet: KSSV am 31 Okt. 2016
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 Kommentare
Image Analyst
Image Analyst am 1 Nov. 2016
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by