필터 지우기
필터 지우기

How to assign a new name for a set of data?

조회 수: 2 (최근 30일)
Nopparat
Nopparat 2012년 8월 31일
I have a set of data such as pic_ab011.tif, pic_ab012.tif, pic_ab013.tif, and so on. I want to get rid of the digits and assign the number whatever we want. For example, the result should be like this. First, all file names will be "pic_ab.tif" and then it will be pic_ab000, pic_ab001, pic_ab002, and so on. Do you have any suggestion? Thank you you guys in advance.
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 8월 31일
Please do not use your own name as one of the tags on the question. You can find your own questions easily by using the "My Questions" link on the left side of the page.

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

채택된 답변

Jan
Jan 2012년 8월 31일
편집: Jan 2012년 8월 31일
There are efficient tools to rename files using the functions of the operating system, see e.g. http://www.howtogeek.com/111859/how-to-batch-rename-files-in-windows-4-ways-to-rename-multiple-files/ or thousands of other tools suggested by your favorite search engine.
When you want to do this in Matlab for unknown but good reasons:
folder = 'C:\Temp\YourFolder\';
list = dir(fullfile(folder, 'pic_ab*.tif'));
nList = length(list);
oldName = {list.name};
newName = regexp(sprintf('pic_ab%.3d*', 0:nList-1), '*', 'split');
for iFile = 1:nList
movefile(fullfile(folder, oldName{iFile}), ...
fullfile(folder, newName{iFile}));
end
As usual the reply of movefile should be checked to show a meaningful error message in case of problems. If you are in a hurry, use the faster FEX: FileRename.
  댓글 수: 1
Nopparat
Nopparat 2012년 8월 31일
It works very well!!! Thanks a lot.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by