There is an exception here. it should be `filename.lastIndexOf(".")`