It's all good, but the idea is to only do the replacement with the random numbers if the file names end in _00001, then remove this part and replace the 9999999 with the random numbers, the other changes to the files like adding the "-" and pad with 0 if less than 7 digits are for all files.