path.Ext()
代码实现如下:
package main
import (
"path"
"fmt"
)
func main(){
filepath := "C:\\Users\\Administrator\\Desktop\\user_agents.py"
fileExt := path.Ext(filepath)
fmt.Println(fileExt)
}
通过这个方法来判断文件的后缀名很方便;
.bmp
package main
import (
"path"
"fmt"
)
func main(){
filepath := "C:\\Users\\Administrator\\Desktop\\user_agents.py"
fileExt := path.Ext(filepath)
if fileExt != ".bmp"{
fmt.Println("file type must be bmp")
}
// ...
}