Go FileExists()

1 개요[ | ]

Go FileExists()
Go
CPU
-1.0s
MEM
-0M
-1.0s
Copy
package main

import (
	"fmt"
	"os"
)

func fileExists(filename string) bool {
	info, err := os.Stat(filename)
	return err == nil && !info.IsDir()
}

func main() {
	// true
	fmt.Println(fileExists("/etc/services")) // File Exists

	// false
	fmt.Println(fileExists("/etc/file-not-exists")) // File Not Exists
	fmt.Println(fileExists("/etc"))                 // Directory Exists
}
true
false
false

2 같이 보기[ | ]

3 참고[ | ]