How to rename images from a series of folder

1 vue (au cours des 30 derniers jours)
Md
Md le 28 Mar 2014
Commenté : Walter Roberson le 24 Déc 2018
Hi All, I worte a code to rename the images in the folders. This is my code.
mainDirectory = 'C:\Users\md\Desktop\NewFolder';
subDirectory = dir([mainDirectory '/N*']);
for m = 1 : length(subDirectory)
a=char('mainDirectory '\' subDirectory(m))');
subFolder = dir(a,'\*.tif');
fileNames = {subFolder.name};
for iFile = 1 : numel( subFolder )
newName = fullfile(subDirectory, sprintf( 'D_1_20%2d.tif',(14-iFile) ) );
movefile( fullfile(subDirectory, fileNames{ iFile }), newName );
end
end
when I run the code, it is saying that too many input arguments. I don't know what I am doing wrong. also there is an error in this line
subFolder = dir(a,'\*.tif');
Thanks in advance.

Réponse acceptée

Marta Salas
Marta Salas le 28 Mar 2014
mainDirectory = 'C:\Users\md\Desktop\NewFolder';
subDirectory = dir([mainDirectory '/N*']);
for m = 1 : length(subDirectory)
subFolder = dir(fullfile(mainDirectory, subDirectory(m).name,'*.tif'));
fileNames = {subFolder.name};
for iFile = 1 : numel( subFolder )
newName = fullfile(mainDirectory, subDirectory(m).name, sprintf( 'D_1_20%2d.tif',(14-iFile) ) );
movefile( fullfile(mainDirectory, subDirectory(m).name, fileNames{ iFile }), newName );
end
end
  3 commentaires
Le Dung
Le Dung le 24 Déc 2018
what is the meaning of '/N*' in the command line:
subDirectory = dir([mainDirectory '/N*']);
When i use the cmmand line, matlab return:
0 x 1 struc with 5 fields
but, when i dont use '/N*', matlab return:
11x1 struc with 5 fields
Is '/N*' for folders and not take into account is for files?
Could you explain to me ?
Walter Roberson
Walter Roberson le 24 Déc 2018
The original poster in 2014, md, happened to be interested in only the subfolders whose names began with the letter N. It is not some kind of special command switch: it is just part of the name.
Another way that it could have been coded would be
subDirectory = dir( fullfile(mainDirectory, 'N*') );
You might have been misled by the fact that a / was used when you expected to see \ for directory names. It turns out that internally, MS DOS has always used / as the directory separator, but that way way back for compatibility with CP/M command line structure that used / as the way to indicate command options, the shell used \ to indicate directory boundaries. But that was only for presentation purposes, and internally it uses / . Therefore in MS Windows, 'C:\Users\md\Desktop\NewFolder' is the same as 'C:/Users/md/Desktop/NewFolder'

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Search Path dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by