"Go 디렉토리 목록 조회"의 두 판 사이의 차이

30번째 줄: 30번째 줄:


[[분류: Go]]
[[분류: Go]]
[[분류: 디렉토리]]

2021년 11월 9일 (화) 16:28 판

1 개요

Go 디렉토리 목록 조회
package main

import (
	"fmt"
	"io/ioutil"
	"log"
)

func main() {
	dirs := []string{}
	files, err := ioutil.ReadDir("/etc")
	if err != nil {
		log.Fatal(err)
	}
	for _, f := range files {
		if f.IsDir() {
			dirs = append(dirs, f.Name())
		}
	}
	fmt.Println(dirs)
}

2 같이 보기

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