Golang os.Stat: 获取文件信息
import("fmt""os")\n\nfunc\ main() {\n\tfilePath\ :=\ "path/to/file.txt"\n\n\tfileInfo, err\ :=\ os.Stat(filePath)\n\tif\ err\ !=\ nil\ {\n\t fmt.Println("Error occurred:", err)\n\t return\n\t}\n\n\tfmt.Println("File name:", fileInfo.Name())\n\tfmt.Println("Size in bytes:", fileInfo.Size())\n\tfmt.Println("Permissions:", fileInfo.Mode())\n\tfmt.Println("Last modified:", fileInfo.ModTime())\n\tfmt.Println("Is directory:", fileInfo.IsDir())\n}
原文地址: http://www.cveoy.top/t/topic/pMw8 著作权归作者所有。请勿转载和采集!