fs

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2022 License: Apache-2.0 Imports: 3 Imported by: 11

README

File System Utilities in Go 1.18+

Go Version GoDoc License Go Report Card

  • file.Touch
  • file.Replace
  • file.Fetch
  • fs.Exists
  • fs.NotExists
  • dir.Entries

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DupPerms added in v0.1.2

func DupPerms(orig, clone string) error

DupPerms duplicates the perms of one file or directory onto the second.

Example
package main

import (
	"fmt"
	"os"

	"github.com/rwxrob/fs"
)

func main() {
	os.Mkdir(`testdata/some`, 0000)
	defer os.Remove(`testdata/some`)
	stats, _ := os.Stat(`testdata/orig`)
	fmt.Println(stats.Mode())
	stats, _ = os.Stat(`testdata/some`)
	fmt.Println(stats.Mode())
	err := fs.DupPerms(`testdata/orig`, `testdata/some`)
	if err != nil {
		fmt.Println(err)
	}
	stats, _ = os.Stat(`testdata/some`)
	fmt.Println(stats.Mode())
}
Output:

drw-------
d---------
drw-------

func Exists added in v0.3.0

func Exists(path string) bool

Exists returns true if the given path was absolutely found to exist on the system. A false return value means either the file does not exists or it was not able to determine if it exists or not. Use NotExists instead.

WARNING: do not use this function if a definitive check for the non-existence of a file is required since the possible indeterminate error state is a possibility. These checks are also not atomic on many file systems so avoid this usage for pseudo-semaphore designs and depend on file locks.

Example
package main

import (
	"fmt"

	"github.com/rwxrob/fs"
)

func main() {
	fmt.Println(fs.Exists("testdata/file")) // use NotExists instead of !
}
Output:

false

func IsDir

func IsDir(path string) bool

IsDir returns true if the indicated path is a directory. Returns false and logs if unable to determine.

Example
package main

import (
	"fmt"

	"github.com/rwxrob/fs"
)

func main() {
	fmt.Println(fs.IsDir("testdata"))
	fmt.Println(fs.IsDir("testdata/fail"))
}
Output:

true
false

func ModTime added in v0.3.0

func ModTime(path string) time.Time

ModTime returns the FileInfo.ModTime() from Stat() as a convenience or returns a zero time if not. See time.IsZero.

Example
package main

import (
	"fmt"

	"github.com/rwxrob/fs"
)

func main() {
	fmt.Println(fs.ModTime("testdata/file").IsZero())
	fmt.Println(fs.ModTime("testdata/none"))
}
Output:

true
0001-01-01 00:00:00 +0000 UTC

func NotExists added in v0.3.0

func NotExists(path string) bool

NotExists definitively returns true if the given path does not exist. See Exists as well.

Example
package main

import (
	"fmt"

	"github.com/rwxrob/fs"
)

func main() {
	fmt.Println(fs.NotExists("testdata/nope")) // use Exists instead of !
}
Output:

true

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL