拡張子のついていないファイルの拡張子をつけたい。

「〇〇〇〇.〇〇〇〇.〇〇〇〇」(〇〇の部分はすべて数字)という拡張子のついていないファイルが大量に存在するフォルダがあります。
このフォルダに存在する全てのファイルに.dcmの拡張子をつけたいのですが、どのようなスクリプトを書けばよいでしょうか。
よろしくお願いいたします。

 Accepted Answer

Kojiro Saito
Kojiro Saito on 7 Apr 2023

1 vote

フォルダーのファイル一覧取得はdirコマンドlsコマンドででき、ファイル名変更はmovefileなどでできます。
imageフォルダーに「〇〇〇〇.〇〇〇〇.〇〇〇〇」のファイルがあると仮定し、全て「〇〇〇〇.〇〇〇〇.〇〇〇〇.dcm」にリネームするサンプルは以下のとおりです。
list = dir("image/*");
list([list.isdir]) = []; % リストから'.'と'..'を削除
for n=1:length(list)
movefile(fullfile(list(n).folder, list(n).name), fullfile(list(n).folder, list(n).name + ".dcm"));
end

1 Comment

秋葉
秋葉 on 10 Apr 2023
dcmファイルに変換できました!
ありがとうございました。

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2022a

Asked:

on 7 Apr 2023

Commented:

on 10 Apr 2023

Community Treasure Hunt

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

Start Hunting!