フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to rename filenames quickly?

2 ビュー (過去 30 日間)
Cody
Cody 2012 年 1 月 24 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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!

回答 (2 件)

Sean de Wolski
Sean de Wolski 2012 年 1 月 24 日

Dr. Seis
Dr. Seis 2012 年 1 月 24 日
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 件のコメント
Dr. Seis
Dr. Seis 2012 年 1 月 24 日
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.

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by