Borrar filtros
Borrar filtros

Changing the names of huge amount of text files?

2 visualizaciones (últimos 30 días)
Gokul  Kanneganti
Gokul Kanneganti el 13 de En. de 2016
Comentada: Stalin Samuel el 13 de En. de 2016
Hi, I have a folder containing 15,369 textfiles with names AP_pcp_016_080.txt etc..I want to change the name of the files to X016Y080 please help me.
  3 comentarios
Gokul  Kanneganti
Gokul Kanneganti el 13 de En. de 2016
how to change the names of 15,000 files at a time?

Iniciar sesión para comentar.

Respuestas (1)

Stalin Samuel
Stalin Samuel el 13 de En. de 2016
Editada: Stephen23 el 13 de En. de 2016
files = dir('*.txt');
for id = 1:length(files)
[~,old_name] = fileparts(files(id).name);
digit_index = regexp(old_name,'\d') ;
numbers = num2str(str2double(old_name(digit_index)));
new_name = strcat('X0',numbers(1:2),'Y',numbers(3:5));
movefile(strcat(old_name,'.txt'), sprintf('%s.txt', new_name));
end
  2 comentarios
Stephen23
Stephen23 el 13 de En. de 2016
@Stalin Samuel: please learn to indent and format your code properly to make it readable. You have answered enough questions on this forum to know that neat, correctly indented code is more readable and less buggy.

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by