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 참고[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.