Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Nopparat
Nopparat le 31 Août 2012
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 commentaire
Walter Roberson
Walter Roberson le 31 Août 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.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 31 Août 2012
Modifié(e) : Jan le 31 Août 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.
  1 commentaire
Nopparat
Nopparat le 31 Août 2012
It works very well!!! Thanks a lot.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by