Maybe create a list. Scan the phone for .jpg files. When one is found, enter the path, file name, and date created into the list. When all files are found, sort the list by date created. Then iterate through the list and rename all the files, using a counter to keep track of the next number to be used.