Use the same code to detect file extension