필터 지우기
필터 지우기

Changing the names of huge amount of text files?

조회 수: 2 (최근 30일)
Gokul  Kanneganti
Gokul Kanneganti 2016년 1월 13일
댓글: Stalin Samuel 2016년 1월 13일
Hi, I have a folder containing 15,369 textfiles with names AP_pcp_016_080.txt etc..I want to change the name of the files to X016Y080 please help me.
  댓글 수: 3
Gokul  Kanneganti
Gokul Kanneganti 2016년 1월 13일
how to change the names of 15,000 files at a time?

댓글을 달려면 로그인하십시오.

답변 (1개)

Stalin Samuel
Stalin Samuel 2016년 1월 13일
편집: Stephen23 2016년 1월 13일
files = dir('*.txt');
for id = 1:length(files)
[~,old_name] = fileparts(files(id).name);
digit_index = regexp(old_name,'\d') ;
numbers = num2str(str2double(old_name(digit_index)));
new_name = strcat('X0',numbers(1:2),'Y',numbers(3:5));
movefile(strcat(old_name,'.txt'), sprintf('%s.txt', new_name));
end
  댓글 수: 2
Stephen23
Stephen23 2016년 1월 13일
@Stalin Samuel: please learn to indent and format your code properly to make it readable. You have answered enough questions on this forum to know that neat, correctly indented code is more readable and less buggy.
Stalin Samuel
Stalin Samuel 2016년 1월 13일
ok

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by