Go语言之进阶篇获取文件属性
1、获取文件属性
示例:
get_file_attribute.go
package main import ( "fmt" "os" ) func main() { list := os.Args if len(list) != 2 { fmt.Println("useage: xxx file") return } fileName := list[1] info, err := os.Stat(fileName) if err != nil { fmt.Println("err = ", err) return } fmt.Println("name = ", info.Name()) fmt.Println("size = ", info.Size()) }
执行结果:
D:\GoFiles\src\hello_01>go run get_file_attribute.go C:\engineering_management\redis.mp4 name = redis.mp4 size = 34585608