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!