Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultPerms = 0700
DefaultPerms are defaults for new directory creation.
Functions ¶
func AddSlash ¶ added in v0.4.2
AddSlash adds a filepath.Separator to the end of all entries passed that are directories.
func Create ¶ added in v0.3.2
Create a new directory with the DefaultPerms creating any new directories as well (see os.MkdirAll)
func Entries ¶
In returns a slice of strings with all the files in the directory at that path joined to their path (as is usually wanted). Returns an empty slice if empty or path doesn't point to a directory. See List.
Example ¶
package main
import (
"fmt"
"github.com/rwxrob/fs/dir"
)
func main() {
list := dir.Entries("testdata")
fmt.Println(list)
}
Output: [testdata/adir testdata/file testdata/other]
func EntriesWithSlash ¶ added in v0.4.2
EntriesWithSlash returns Entries passed to AddSlash so that all directories will have a trailing slash.
func Exists ¶ added in v0.4.3
Exists calls fs.Exists and further confirms that the path is a directory and not a file.
Example ¶
package main
import (
"fmt"
"github.com/rwxrob/fs/dir"
)
func main() {
fmt.Println(dir.Exists("testdata/exists"))
fmt.Println(dir.Exists("testdata"))
}
Output: false true
func HereOrAbove ¶ added in v0.5.2
HereOrAbove returns the full path to the dir if the dir is found in the current working directory, or if not exists in any parent directory recursively.
Example (Above) ¶
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/rwxrob/fs/dir"
)
func main() {
_dir, _ := os.Getwd()
defer func() { os.Chdir(_dir) }()
os.Chdir("testdata/adir/anotherdir")
path, err := dir.HereOrAbove("adir")
if err != nil {
fmt.Println(err)
}
d := strings.Split(path, string(filepath.Separator))
fmt.Println(d[len(d)-2:])
}
Output: [testdata adir]
Example (Here) ¶
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/rwxrob/fs/dir"
)
func main() {
_dir, _ := os.Getwd()
defer func() { os.Chdir(_dir) }()
os.Chdir("testdata/adir")
path, err := dir.HereOrAbove("anotherdir")
if err != nil {
fmt.Println(err)
}
d := strings.Split(path, string(filepath.Separator))
fmt.Println(d[len(d)-2:])
}
Output: [adir anotherdir]
Types ¶
This section is empty.