How to assign a new name for a set of data?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Walter Roberson
am 31 Aug. 2012
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.
Akzeptierte Antwort
Jan
am 31 Aug. 2012
Bearbeitet: Jan
am 31 Aug. 2012
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!