github.com/goki/ki@v1.1.17/dirs/fs.go (about)

     1  // Copyright (c) 2023, The GoKi Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package dirs
     6  
     7  import (
     8  	"io/fs"
     9  	"os"
    10  	"path/filepath"
    11  )
    12  
    13  // DirFS returns the directory part of given file path as an os.DirFS
    14  // and the filename as a string.  These can then be used to access the file
    15  // using the FS-based interface, consistent with embed and other use-cases.
    16  func DirFS(fpath string) (fs.FS, string, error) {
    17  	fabs, err := filepath.Abs(fpath)
    18  	if err != nil {
    19  		return nil, "", err
    20  	}
    21  	dir, fname := filepath.Split(fabs)
    22  	dfs := os.DirFS(dir)
    23  	return dfs, fname, nil
    24  }