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

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

 Risposta accettata

Kojiro Saito
Kojiro Saito il 7 Apr 2023

1 voto

フォルダーのファイル一覧取得は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 Commento

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

Accedi per commentare.

Più risposte (0)

Categorie

Prodotti

Release

R2022a

Community Treasure Hunt

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

Start Hunting!