How to get all files with a specific name in a folder?

조회 수: 1 (최근 30일)
Stelios Fanourakis
Stelios Fanourakis 2018년 4월 27일
댓글: Stelios Fanourakis 2018년 4월 29일
Hi. I have a sequence of images (without extension) named S000009, S0000010, S0000011,.... There is no extension. They are just files but basically they are dicom images without the .dcm extension. I want to gather them altogether and dicomwrite them. Add the .dcm extension to them. Any idea?
Thank you

채택된 답변

KSSV
KSSV 2018년 4월 27일
files = dir(); % you are in the folder where files are present
N = length(files) ;
for i = 3:N
oldfile = files(i).name ;
newfile = strcat(oldfile,'.dcm') ;
movefile(oldfile,newfile,'f');
end
  댓글 수: 2
Stelios Fanourakis
Stelios Fanourakis 2018년 4월 28일
Thanks a lot. Exactly what I needed.
Stelios Fanourakis
Stelios Fanourakis 2018년 4월 29일
Dear KSSV Your code is perfect. But I need a close that determines if the files have already a .dcm extension and not add them the dcm extension again and again whenever I run the script. For instance, I run the script twice and I got S0009.dcm.dcm. I probably get S0009.dcm.dcm.dcm if I run it for third time. Any idea? Thanks in advance

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by