"Go FileExists()"의 두 판 사이의 차이

 
10번째 줄: 10번째 줄:
)
)


func FileExists(filename string) bool {
func fileExists(filename string) bool {
info, err := os.Stat(filename)
info, err := os.Stat(filename)
return err == nil && !info.IsDir()
return err == nil && !info.IsDir()
17번째 줄: 17번째 줄:
func main() {
func main() {
// true
// true
fmt.Println(FileExists("/etc/services")) // File Exists
fmt.Println(fileExists("/etc/services")) // File Exists


// false
// false
fmt.Println(FileExists("/etc/file-not-exists")) // File Not Exists
fmt.Println(fileExists("/etc/file-not-exists")) // File Not Exists
fmt.Println(FileExists("/etc"))                // Directory Exists
fmt.Println(fileExists("/etc"))                // Directory Exists
}
}
</syntaxhighlight>
</syntaxhighlight>

2023년 5월 13일 (토) 13:44 기준 최신판

1 개요[ | ]

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

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}