Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

How to rename filenames quickly?

2 visualizaciones (últimos 30 días)
Cody
Cody el 24 de En. de 2012
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
I have a bunch of files having the following pattern,
3D_TriaG_t1_dm_de_a_total_vs_wavelength__slice_0_0.dat 3D_TriaG_t1_dm_de_a_total_vs_wavelength__slice_0_1.dat 3D_TriaG_t1_dm_de_a_total_vs_wavelength__slice_1_0.dat 3D_TriaG_t1_dm_de_a_total_vs_wavelength__slice_1_1.dat 3D_TriaG_t2_dm_de_a_total_vs_wavelength__slice_0_0.dat 3D_TriaG_t2_dm_de_a_total_vs_wavelength__slice_0_1.dat 3D_TriaG_t2_dm_de_a_total_vs_wavelength__slice_1_0.dat 3D_TriaG_t2_dm_de_a_total_vs_wavelength__slice_1_1.dat
........
And so on, I want to rename these files into the following simplified format:
t1_0_0.dat
t1_0_1.dat
t1_1_0.dat
t1_1_1.dat
t2_0_0.dat
t2_0_1.dat
t2_1_0.dat
t2_1_1.dat
....
Any one knows how I can do this? Any help is greatly appreciated!

Respuestas (2)

Sean de Wolski
Sean de Wolski el 24 de En. de 2012

Dr. Seis
Dr. Seis el 24 de En. de 2012
Using a trick I recently learned, after you have used the info in Sean's link to determine and store the names of the files in a cell string, you can:
files = {'A_B1_C_D_0_0.dat';
'A_B1_C_D_0_1.dat';
'A_B1_C_D_1_0.dat';
'A_B1_C_D_1_1.dat';
'A_B2_C_D_0_0.dat';
'A_B2_C_D_0_1.dat';
'A_B2_C_D_1_0.dat';
'A_B2_C_D_1_1.dat'};
splt = regexpi(files,'\_','split')
catsplt = cat(1,splt{:});
for i = 1 : numel(files)
%disp(sprintf('%s_%s_%s',...
catsplt{i,2},catsplt{i,5},catsplt{i,6}));
movefile(files{i},sprintf('%s_%s_%s',...
catsplt{i,2},catsplt{i,5},catsplt{i,6}));
end
Use "disp" to print out the result as a QC before you execute the "movefile" command.
  1 comentario
Dr. Seis
Dr. Seis el 24 de En. de 2012
I am splitting up the names of the files based on "_" as a delimiter. Then I am using the 2nd, 5th, and 6th parts of the split filename to generate a new filename.

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by