why lastIndexOf here?  You're more likely to find this string near the beginning of the filename, so use indexOf, I think.