Go FileExists()

Jmnote (토론 | 기여)님의 2021년 12월 30일 (목) 15:20 판 (→‎개요)

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 }}