Go DirExists()

1 개요[ | ]

Go DirExists()
package main

import (
	"fmt"
	"os"
)

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

func main() {
	// true
	fmt.Println(DirExists("/etc"))  // Directory Exists
	fmt.Println(DirExists("/etc/")) // Directory Exists

	// false
	fmt.Println(DirExists("/etc/services"))   // File Exists
	fmt.Println(DirExists("/etc/not-exists")) // Not Exists
}

2 같이 보기[ | ]

3 참고[ | ]

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