How to assign a new name for a set of data?
2 次查看(过去 30 天)
显示 更早的评论
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
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
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!