Skip to content

alexeyco/filesystem

Repository files navigation

File system abstraction

Travis Coverage Status Go Report Card GoDoc license

Work in progress!

  1. Install
  2. Filesystem manipulations
    1. List directory contents
    2. Deep inside directories
    3. Check path
    4. Path info
    5. Create directories
    6. Rename
    7. Remove
  3. Seekers
  4. License

Install

$ go get -u github.com/alexeyco/filesystem

Filesystem manipulations

root, err := filesystem.Root("/path/to/root/directory")
if err != nil {
    log.Fatalln(err)
}

List directory contents

Directories:

err := root.Each().Dir(func(dir *filesystem.Dir) {
    fmt.Println("Dir:  ", dir.Name())
})

Files:

err = root.Each().File(func(file *filesystem.File) {
    fmt.Println("File: ", file.Name())
})

Anything:

err = root.Each().Entry(func(entry filesystem.Entry) {
    fmt.Println("Entry: ", entry.Name())
})

Deep inside directories

err = root.Read(filesystem.Deep()).Each().Entry(func(entry filesystem.Entry) {
    if entry.IsDir() {
        fmt.Println("Dir:  ", entry.Name())
    } else {
        fmt.Println("File: ", entry.Name())
    }
})

Check path

Check path exists:

exist := root.Exist("path/to/file")

Check path is a directory:

exist := root.IsDir("path/to/directory")

Check path is a file:

exist := root.IsFile("path/to/file")

Path info

Get directory:

dir, err := root.Dir("path/to/dir")

Get file:

file, err := root.Dir("path/to/file")

Create directories

Create directory:

err = root.Mkdir("path/to/directory")

Move/rename

Rename files and directories:

err = root.Move("path/to/source", "path/to/dest")

Remove

Remove files and directories:

err = root.Move("path/to/source", "path/to/dest")

License

MIT License

Copyright (c) 2018 Alexey Popov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Releases

No releases published

Packages

No packages published

Languages