github.com/blend/go-sdk@v1.20220411.3/profanity/list_dir.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package profanity
     9  
    10  import (
    11  	"os"
    12  )
    13  
    14  // ListDir reads the directory named by dirname and returns
    15  // a sorted list of directory entries.
    16  func ListDir(path string) (dirs []os.FileInfo, files []os.FileInfo, err error) {
    17  	var f *os.File
    18  	f, err = os.Open(path)
    19  	if err != nil {
    20  		return
    21  	}
    22  	defer f.Close()
    23  
    24  	var children []os.FileInfo
    25  	children, err = f.Readdir(-1)
    26  	if err != nil {
    27  		return
    28  	}
    29  	for _, child := range children {
    30  		if child.IsDir() {
    31  			dirs = append(dirs, child)
    32  		} else {
    33  			files = append(files, child)
    34  		}
    35  	}
    36  	return
    37  }