필터 지우기
필터 지우기

Renaming of image filenames inside the folder

조회 수: 3 (최근 30일)
Turbulence Analysis
Turbulence Analysis 2024년 4월 1일
댓글: Turbulence Analysis 2024년 4월 1일
Hi,
I have 9721 .bmp images stored inside the folder with file names starting from C001H001S0001000001 to C001H001S0001009721, I need to rename all the images to D00001 - D09721. May I know how to do this?

채택된 답변

Amish
Amish 2024년 4월 1일
Hi,
Assuming that all of the '.bmp' files are stored in the same folder, the renaming can be done using a MATLAB script using a 'for' loop to iterate over all the images. This can be done as follows:
directory = 'path/to/your/images'; % Replace this with the path to your images
% Get a list of all files in the folder
files = dir(fullfile(directory, '*.bmp'));
for idx = 1:length(files)
oldName = files(idx).name;
% Extract the numeric part of the original filename
numStr = oldName(14:19);
num = str2double(numStr);
% Generate the new filename
newName = sprintf('D%05d.bmp', num);
% Full path for old and new names
oldFullPath = fullfile(directory, oldName);
newFullPath = fullfile(directory, newName);
% Rename the file
movefile(oldFullPath, newFullPath);
end
Hope this helps!
  댓글 수: 2
Turbulence Analysis
Turbulence Analysis 2024년 4월 1일
Thanks!
I think the below part of code needs to be modified. It would be better to replace the entire old file name by new name rather than extracting the numeric part of the original name.
numStr = oldName(14:19);
num = str2double(numStr);
Turbulence Analysis
Turbulence Analysis 2024년 4월 1일
I have modified another code from different forum, which works fine.
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by