function file_name_new = file_name_inc ( file_name ) % FILE_NAME_INC generates the next filename in a series. % % Discussion: % % It is assumed that the digits in the name, whether scattered or % connected, represent a number that is to be increased by 1 on % each call. If this number is all 9's on input, the output number % is all 0's. Non-numeric letters of the name are unaffected, and % if the name contains no digits, then nothing is done. % % Examples: % % Input Output % ----- ------ % a7to11.txt a7to12.txt % a7to99.txt a8to00.txt % a9to99.txt a0to00.txt % cat.txt cat.txt % % Modified: % % 15 August 2005 % % Author: % % John Burkardt % % Parameters: % % Input, character FILE_NAME(*), the string to be incremented. % % Output, character FILE_NAME_NEW(*), the incremented string. % lens = length ( file_name ); file_name_new = file_name; for i = lens : -1 : 1 c = file_name_new(i); if ( '0' <= c & c <= '8' ) c = c + 1; file_name_new(i) = c; return elseif ( c == '9' ) c = '0'; file_name_new(i) = c; end end