github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/filesystem/directory.go (about)

     1  package filesystem
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  )
     7  
     8  // DirectoryContentsByPath returns the contents of the directory at the
     9  // specified path. The ordering of the contents is non-deterministic.
    10  func DirectoryContentsByPath(path string) ([]os.FileInfo, error) {
    11  	// Open the directory and ensure its closure.
    12  	directory, err := os.Open(path)
    13  	if err != nil {
    14  		return nil, fmt.Errorf("unable to open directory: %w", err)
    15  	}
    16  	defer directory.Close()
    17  
    18  	// Grab the directory contents.
    19  	contents, err := directory.Readdir(0)
    20  	if err != nil {
    21  		return nil, fmt.Errorf("unable to read directory contents: %w", err)
    22  	}
    23  
    24  	// Success.
    25  	return contents, nil
    26  }