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

11 vues (au cours des 30 derniers jours)
秋葉
秋葉 le 7 Avr 2023
Commenté : 秋葉 le 10 Avr 2023
「〇〇〇〇.〇〇〇〇.〇〇〇〇」(〇〇の部分はすべて数字)という拡張子のついていないファイルが大量に存在するフォルダがあります。
このフォルダに存在する全てのファイルに.dcmの拡張子をつけたいのですが、どのようなスクリプトを書けばよいでしょうか。
よろしくお願いいたします。

Réponse acceptée

Kojiro Saito
Kojiro Saito le 7 Avr 2023
フォルダーのファイル一覧取得は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 commentaire
秋葉
秋葉 le 10 Avr 2023
dcmファイルに変換できました!
ありがとうございました。

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur ファイルの操作 dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!