Categorygithub.com/enr/go-files
module
0.3.0
Repository: https://github.com/enr/go-files.git
Documentation: pkg.go.dev

# README

Go files

CI Linux CI Windows PkgGoDev Go Report Card

Shortcuts for operations pertaining files.

Import the library:

import (
    "github.com/enr/go-files/files"
)

Check if path exists (is a file or a directory):

NOTE: There are some good reasons why this function is not implemented in the standard lib (see https://github.com/golang/go/issues/1312) but, if you have to simply check if a file exists in this very moment, it is useful to have a one liner.

e := files.Exists(fpath)

Check if path is a regular file:

e := files.IsRegular(fpath)

Check if path is a directory:

is := files.IsDir(fpath)

Check if path is a symlink:

e := files.IsSymlink(fpath)

Get the Sha1 checksum:

sha1sum, err := files.Sha1Sum(fpath)
if err != nil {
    // ...
}

Copy file to file:

err := files.Copy(srcpath, destpath)
if err != nil {
    // ...
}

Copy file in directory:

err := files.Copy(fpath, destpath)
if err != nil {
    // ...
}

Copy directory recursively:

err := files.CopyDir(source, destination)
if err != nil {
    // ...
}

Read file lines:

lines, err := files.ReadLines(fpath)
if err != nil {
    // ...
}

Process file lines:

files.EachLine(path, func(line string) error {
    fmt.Println(" # " + line)
    return nil
})

License

Apache 2.0 - see LICENSE file.

Copyright 2014 go-files contributors

# Packages

No description provided by the author