フォルダ内の特定のフ​ァイルを別ファイルに​移動したいです。

조회 수: 14 (최근 30일)
秋葉
秋葉 2022년 12월 11일
댓글: 秋葉 2022년 12월 19일
フォルダ内に入れている大量のdicomファイルを読み込んでいたのですが、特定の複数のdicomファイルのみ
警告: 問題のありそうな断片的なファイルです。DICOM ではない可能性があります。
などのエラーが出てきてしまいます。
そこで、警告が出てきてしまうファイルのみ別フォルダに移動させたいのですが、どのようなスクリプトを書けばよいのでしょうか。

채택된 답변

Atsushi Ueno
Atsushi Ueno 2022년 12월 11일
편집: Atsushi Ueno 2022년 12월 11일
cur = pwd;
copyfile('/MATLAB/toolbox/matlab/imagesci/peppers.png',cur);
copyfile('/MATLAB/toolbox/images/imdata/CT-MONO2-16-ankle.dcm',cur);
copyfile('/MATLAB/toolbox/images/imdata/US-PAL-8-10x-echo.dcm',cur);
movefile peppers.png peppers.dcm % peppers.pngを偽のdcmファイルにしておく
mkdir temp % 空のtempフォルダを作成
ls -la % ここまでサンプルデータの作成です
total 1288 drwxr-xr-x 3 mluser worker 4096 Dec 11 21:54 . drwx------ 1 mluser worker 4096 Dec 11 21:54 .. -r-xr-xr-x 1 mluser worker 525436 Dec 18 2000 CT-MONO2-16-ankle.dcm -r--r--r-- 1 mluser worker 287677 Dec 16 2002 peppers.dcm drwxr-xr-x 2 mluser worker 4096 Dec 11 21:54 temp -r-xr-xr-x 1 mluser worker 483610 Dec 18 2000 US-PAL-8-10x-echo.dcm
list_dicom = dir([pwd,filesep,'*.dcm']);
for j = 1:size(list_dicom,1)
warning('') % 最後のワーニングメッセージを削除
data{j} = dicomread([list_dicom(j).folder,filesep,list_dicom(j).name]);
[warnMsg, warnId] = lastwarn;
if ~isempty(warnMsg)
movefile([list_dicom(j).folder,filesep,list_dicom(j).name] ...
,[cur,filesep,'temp',filesep,list_dicom(j).name])
end
end
Warning: Suspicious fragmentary file, might not be DICOM.
Warning: Not enough data imported. Attempted to read 169478669 bytes at position 8. Only read 287669.
ls -la
total 1004 drwxr-xr-x 3 mluser worker 4096 Dec 11 21:54 . drwx------ 1 mluser worker 4096 Dec 11 21:54 .. -r-xr-xr-x 1 mluser worker 525436 Dec 18 2000 CT-MONO2-16-ankle.dcm drwxr-xr-x 2 mluser worker 4096 Dec 11 21:54 temp -r-xr-xr-x 1 mluser worker 483610 Dec 18 2000 US-PAL-8-10x-echo.dcm
ls temp -la
total 292 drwxr-xr-x 2 mluser worker 4096 Dec 11 21:54 . drwxr-xr-x 3 mluser worker 4096 Dec 11 21:54 .. -r--r--r-- 1 mluser worker 287677 Dec 16 2002 peppers.dcm
偽のpeppers.dcmファイルがtempフォルダに移動された事を確認しました。
  댓글 수: 1
秋葉
秋葉 2022년 12월 19일
遅くなってしまい申し訳ございません.
ありがとうございました.
助かりました.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!