How to iteratively increase number in filename?
Show older comments
I have a list of files named ######-######-####XX, where # is an arbitrary number (same for all files), and XX is 01:20. I'm trying to rename all the files by adding 1 to the frame number, so the files will effectively go from 02:21. I tried using the code below, but soon realized that adding 1 to 9 will not make 19 go to 20. Does anyone have a better solution for this? Thanks in advance.
list=dir('*.dcm')
names={list.name}
for m=1:length(list)
revnames=names(end:-1:1)
[~,name,ext]=fileparts(revnames{m})
OldName=[name,ext]
A=num2str(name)
A(end)=(A(end)+1)
NewName=[A,ext]
copyfile(OldName,NewName)
clear A
end
Accepted Answer
More Answers (0)
Categories
Find more on File Operations 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!