Filter löschen
Filter löschen

Rename files in a directory

24 Ansichten (letzte 30 Tage)
Tala Hed
Tala Hed am 26 Feb. 2018
Kommentiert: Tala Hed am 26 Feb. 2018
Dear Experts, I have 50 csv files and want to rename them. The current names are 10.csv, 20.csv, ...700.csv and want to rename them to data1.csv, data2.csv,...data70.csv. They are all in matlab directory. Can you please help me :)

Akzeptierte Antwort

Akira Agata
Akira Agata am 26 Feb. 2018
Another possible solution:
f = dir('*.csv');
for kk = 1:numel(f)
fileFrom = f(kk).name;
fileTo = ['data',erase(f(kk).name,'0.csv'),'.csv'];
movefile(fileFrom,fileTo);
end

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 26 Feb. 2018
Adapting the example from the documentation of using that contribution:
D = 'C:\Test';
S = dir(fullfile(D,'*.csv'));
N = natsortfiles({S.name});
for k = 1:numel(N)
sourcefile = fullfile(D, N{k});
destfile = fullfile(D, sprintf('data%d.csv', k));
movefile(sourcefile, destfile);
end

Kategorien

Mehr zu Data Import and Analysis 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