Info
此问题已关闭。 请重新打开它进行编辑或回答。
How to rename filenames quickly?
1 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(2 个)
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
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!