How to rename images from a series of folder
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Marta Salas
2014년 3월 28일
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
Le Dung
2018년 12월 24일
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
2018년 12월 24일
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'
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Search Path에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!