フィルターのクリア

Rename files in a directory

25 ビュー (過去 30 日間)
Tala Hed
Tala Hed 2018 年 2 月 26 日
コメント済み: Tala Hed 2018 年 2 月 26 日
Dear Experts, I have 50 csv files and want to rename them. The current names are 10.csv, 20.csv, ...700.csv and want to rename them to data1.csv, data2.csv,...data70.csv. They are all in matlab directory. Can you please help me :)

採用された回答

Akira Agata
Akira Agata 2018 年 2 月 26 日
Another possible solution:
f = dir('*.csv');
for kk = 1:numel(f)
fileFrom = f(kk).name;
fileTo = ['data',erase(f(kk).name,'0.csv'),'.csv'];
movefile(fileFrom,fileTo);
end
  1 件のコメント
Tala Hed
Tala Hed 2018 年 2 月 26 日
Thanks a million Akira.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 2 月 26 日
Adapting the example from the documentation of using that contribution:
D = 'C:\Test';
S = dir(fullfile(D,'*.csv'));
N = natsortfiles({S.name});
for k = 1:numel(N)
sourcefile = fullfile(D, N{k});
destfile = fullfile(D, sprintf('data%d.csv', k));
movefile(sourcefile, destfile);
end

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by