I think this breaks if the filename has no extension -- slice(0, -1) removes the last char.