Go FileExists()

Jmnote (토론 | 기여)님의 2023년 5월 13일 (토) 13:44 판 (→‎개요)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

Go FileExists()
Go
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
}
Loading

2 같이 보기[ | ]

3 참고[ | ]