Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

How to rename filenames quickly?

2 visualizzazioni (ultimi 30 giorni)
Cody
Cody il 24 Gen 2012
Chiuso: MATLAB Answer Bot il 20 Ago 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!

Risposte (2)

Sean de Wolski
Sean de Wolski il 24 Gen 2012

Dr. Seis
Dr. Seis il 24 Gen 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 Commento
Dr. Seis
Dr. Seis il 24 Gen 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.

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by