Fix the error of the getNextFileName function