필터 지우기
필터 지우기

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 CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by