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

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

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 11 Dec 2022
Edited: Atsushi Ueno on 11 Dec 2022
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 Comment
秋葉
秋葉 on 19 Dec 2022
遅くなってしまい申し訳ございません.
ありがとうございました.
助かりました.

Sign in to comment.

More Answers (0)

Categories

Find more on DICOM Format in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!