{"id":1132,"date":"2020-01-15T15:38:21","date_gmt":"2020-01-15T15:38:21","guid":{"rendered":"https:\/\/golangbyexamples.com\/?p=1132"},"modified":"2020-01-15T15:38:29","modified_gmt":"2020-01-15T15:38:29","slug":"check-if-file-is-a-directory-go","status":"publish","type":"post","link":"https:\/\/golangbyexamples.com\/check-if-file-is-a-directory-go\/","title":{"rendered":"Check if file is a directory or not in Go (Golang)"},"content":{"rendered":"\n
See the below code to know if a file is a file or it is a directory
<\/p>\n\n\n\n
package main\n\nimport (\n \"fmt\"\n \"log\"\n \"os\"\n)\n\nvar (\n fileInfo *os.FileInfo\n err error\n)\n\nfunc main() {\n info, err := os.Stat(\"temp\")\n if os.IsNotExist(err) {\n log.Fatal(\"File does not exist.\")\n }\n if info.IsDir() {\n fmt.Println(\"temp is a directory\")\n } else {\n fmt.Println(\"temp is a file\")\n }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"See the below code to know if a file is a file or it is a directory If temp is a file output will be = “temp is a file” If temp…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[154],"class_list":["post-1132","post","type-post","status-publish","format-standard","hentry","category-tech","tag-directory"],"yoast_head":"\n
Check if file is a directory or not in Go (Golang) - Welcome To Golang By Example<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n