필터 지우기
필터 지우기

rename photos in a specific folder

조회 수: 3 (최근 30일)
Mohanned Al Gharawi
Mohanned Al Gharawi 2021년 1월 1일
댓글: Image Analyst 2021년 1월 2일
Hello everybody,
I have a set of photos in a specific folder. Let say they start from Image00000_IR1 to Image00100_IR1. What I want is to rename these photos, so they will become Image00101_IR1 to Image00199_IR1. Is there a way that we could do that in MATLAB?
Thanks in advance.
  댓글 수: 3
Mohanned Al Gharawi
Mohanned Al Gharawi 2021년 1월 2일
편집: Stephen23 2021년 1월 2일
I think that would not work with a folder that contains a hendred photo.
Should I put it in a loop or something?
Anyhow, I got a code from someone and I did it on my photos and I got an error says "Cannot copy or move a file or directory onto itself."
The code is:
base = 'F:\(second week)\Position1 - Copy'; % Set accordingly
list = dir(fullfile(base, '*.mim'));
for iList = 1:numel(list)
name = list(iList).name;
index = strfind(name, '.'); % Example, use "20110331093455.dcm"
newName = (name(1:index(1)-1));
% newName = ('Image10001_IR1');
movefile(fullfile(base, name), fullfile(base, [newName, '.mim']));
end
I dont know where is my error? Could you help me with that?
Stephen23
Stephen23 2021년 1월 2일
"I dont know where is my error?"
The orignal name and the new name are exactly the same. It appears that you might want to change the file extension, but your code just uses exactly the same file extension.
The robust and recommended way to split the filename and file extension is to use fileparts, rather than messing about with indexing like this code does.

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

답변 (1개)

Image Analyst
Image Analyst 2021년 1월 2일
Why can't you just essentially follow the way I did it in your almost identical question:
  댓글 수: 2
Mohanned Al Gharawi
Mohanned Al Gharawi 2021년 1월 2일
I did the code but there are no files in the folder Renmed!
Image Analyst
Image Analyst 2021년 1월 2일
See my reply over there.

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

카테고리

Help CenterFile Exchange에서 Adding custom doc에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by