Borrar filtros
Borrar filtros

Rename files in a directory

25 visualizaciones (últimos 30 días)
Tala Hed
Tala Hed el 26 de Feb. de 2018
Comentada: Tala Hed el 26 de Feb. de 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 :)

Respuesta aceptada

Akira Agata
Akira Agata el 26 de Feb. de 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

Más respuestas (1)

Walter Roberson
Walter Roberson el 26 de Feb. de 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

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by