Use pathinfo to get file extension instead of string operations