Filter löschen
Filter löschen

Renames a lot of files in directory

1 Ansicht (letzte 30 Tage)
Oktavian Jason
Oktavian Jason am 3 Mär. 2020
Kommentiert: Oktavian Jason am 3 Mär. 2020
Hello, I have a lot of .mat files in a folder and I want to rename it from ex : 65300106179 into something like Flight 10001 and so on. Below is my code
f = dir( fullfile( projectdir, '**', '*.mat') );
for kk = 1:numel(f)
fileFrom = f(kk).name;
fileTo = ['Flight',erase(f(kk).name,'1000%d.mat'),'.mat'];
movefile(fileFrom,fileTo);
end
The problem I have is the file name changed into Flight65300106179.mat. Any idea where I did wrong?

Akzeptierte Antwort

KSSV
KSSV am 3 Mär. 2020
f = dir( fullfile( projectdir, '**', '*.mat') );
for kk = 1:numel(f)
fileFrom = f(kk).name;
fileTo = ['Flight','1000%d.mat','.mat'];
movefile(fileFrom,fileTo);
end
  6 Kommentare
Oktavian Jason
Oktavian Jason am 3 Mär. 2020
thank you
Oktavian Jason
Oktavian Jason am 3 Mär. 2020
Do you have any idea how I can rename on subfolder too?
Example : Folder A : Flight 10001-Flight 10010, Folder B : Flight 10011-Flight 10020

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Bhaskar R
Bhaskar R am 3 Mär. 2020
fileTo = sprintf('Flight 1000%d.mat',kk);

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by