Change names of files in a folder
Show older comments
Hi I am trying to change all the file names in a folder I have of .tif images. I want to use the number of tif images in the file to be apart of the new save name.
INDIV = 'folder_path'; %
filenames_INDIV = dir(fullfile(INDIV, '*.tif')); % <-- 126x1 struct
original_images_indv = numel(filenames_INDIV); % <-- 126
for g = 1 : filenames_INDIV
for h = 1 : original_images_indv
[~, f] = fileparts(filenames_INDIV(h).name);
% write the rename file
rf = strcat(f,'SAM%03d', h) ;
% rename the file
movefile(filenames_INDIV(h).name, rf);
end
end
But I end up getting
Undefined function 'colon' for input arguments of type 'struct' for the first for statement
2 Comments
Adam
on 22 Oct 2019
Well, yes, as your own comments tell you filenames_INDIV is a (126x1) struct so using it as
1:filenames_INDIV
clearly won't work. I guess you could use
1:numel( filenames_INDIV )
although it isn't obvious to me what the outer loop does anyway since g is never referenced.
no zoop
on 22 Oct 2019
Accepted Answer
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!