Backport filename_from_template routine from SWB to handle leading zeroes in filenames.