Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

Walter Roberson
Walter Roberson le 31 Oct 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

Plus de réponses (1)

KSSV
KSSV le 31 Oct 2016
Modifié(e) : KSSV le 31 Oct 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 commentaires
Image Analyst
Image Analyst le 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
Aditya Palsule
Aditya Palsule le 2 Nov 2016
Image, thanks a lot for informing me about it. I had never checked it out.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by