Check if Path Points to File or Directory

Posted by yhuang
Public (Editable by Users)
Go
Edit
package main

import (
	"fmt"
	"os"
)

func main() {

	file, e := os.Stat("/some/path")
	if e != nil {
		panic(e)
	}

	mode := file.Mode()
	if mode.IsDir() {
		fmt.Println("directory")
	} else if mode.IsRegular() {
		fmt.Println("file")
	}
}