필터 지우기
필터 지우기

How to remove/rename part of a file name in a loop?

조회 수: 23 (최근 30일)
Monique Embury
Monique Embury 2019년 8월 20일
댓글: Monique Embury 2019년 8월 21일
Hi,
I am trying to rename 50,000 images that have an incorrect file name. They are all .tif files with a name similar to "Hoverdofeightnosleevetriggered000002.T000.D000.P000.H000.LA" and should be named like this "Hoverdofeightnosleevetriggered000001A". The files start at 0 and increase from there. Everyother photo is called A or B. Can someone please help me rename them in a loop?
I have looked online and can't seem to find a code that will work.
Thanks in advance!
  댓글 수: 2
the cyclist
the cyclist 2019년 8월 20일
I don't understand the general rule for renaming the files. Could you give a couple more examples of input/output?
Monique Embury
Monique Embury 2019년 8월 20일
In the attached image, the first four names are done manually and correctly. The last four file names are the original input files. All existing files need to be renamed like the first four.
It would be helpful to use a loop since I have close to 50,000 images to rename.
example for file names.PNG

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

채택된 답변

Rik
Rik 2019년 8월 20일
편집: Rik 2019년 8월 20일
Something like this should work. Adapt as needed.
list=dir('Hoverdofeightnosleevetriggered*.*');
for n=1:numel(list)
old=list(n).name;
new=strrep(list(n).name,'.T000.D000.P000.H000.L','');
movefile(old,new);
end

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by