필터 지우기
필터 지우기

How to rename .m files

조회 수: 30 (최근 30일)
Harish Patil
Harish Patil 2015년 6월 15일
댓글: Walter Roberson 2015년 10월 13일
In my current directory bunch of XXX.mat files to be rename as XXXNewname.mat files using MATLAB command prompt . Anyone knows ????

채택된 답변

Walter Roberson
Walter Roberson 2015년 6월 15일
newstr = 'Newname';
dinfo = dir('*.mat');
for K = 1 : length(dinfo)
thisfile = dinfo(K).name;
[pathstr, base, ext] = fileparts(thisfile);
if strncmp( fliplr(base), fliplr(newstr), length(newstr) ) %compare ends
continue; %this one has already been renamed
end
newfid = fullfile(pathstr, [base newstr ext]);
movefile(thisfile, newfid);
end
  댓글 수: 3
Harish Patil
Harish Patil 2015년 10월 13일
Hi Walter Roberson , I have a another doubt : Except 2 files in my directory I need to rename all files.... can you please help the same.
Walter Roberson
Walter Roberson 2015년 10월 13일
folderinfo = folderinfo(~ismember({folderinfo.name}, {'.', '..'})); %remove directories . and ..
but adapt that for dinfo and the two names you want to leave alone

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by