特定の倍数番目のファイルのみを別フォルダに移動したいです。
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
現在、あるフォルダAの中にファイル名が
0001.jpg
0002.jpg
...8730.jpg
という名前のjpgファイルを作成しているのですが、この中のファイル名が30の倍数の番号のみ別フォルダBに移行したいと考えております。
この場合どのようなスクリプトを書けばよいか教えていただけないでしょうか。
0 commentaires
Réponse acceptée
Atsushi Ueno
le 21 Déc 2022
% ファイルを8730個作る
mkdir A; movefrom = [pwd '/A']; % 移動元
mkdir B; moveto = [pwd '/B']; % 移動先
for i = 1:8730
fclose(fopen([movefrom,filesep,sprintf('%04d.jpg',i)],'w'));
end
% 30の倍数のファイル名だけ移動する
for i = 30:30:8730
mvfr = [movefrom,filesep,sprintf('%04d.jpg',i)]; % 移動元
mvto = [moveto ,filesep,sprintf('%04d.jpg',i)]; % 移動先
if isfile(mvfr)
movefile(mvfr,mvto); % ファイルが在ったら移動
end
end
ls B
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur ファイルの操作 dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!