Popularity
1.4
Stable
Activity
0.0
Stable
13
2
3

Programming language: Go
License: MIT License
Tags: File Handling    

pathtype alternatives and similar packages

Based on the "File Handling" category.
Alternatively, view pathtype alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of pathtype or a related project?

Add another 'File Handling' Package

README

pathtype

Treat paths as their own type instead of using strings. This small package wraps functions from the standard library to create a new Path type.

Example

Code

package main

import (
    "fmt"
    "log"

    pt "github.com/jonchun/pathtype"
)

type path = pt.Path

func main() {
    myFile := path("myfile.txt")
    exampleFile := path("example/example.txt")
    fmt.Println(exampleFile.Dir())
    fmt.Println(exampleFile.Dir().Join(myFile))

    res, err := exampleFile.Dir().Join(myFile).Dir().Abs()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(res)

    fmt.Println("=========================")
    listBase(res)
    fmt.Println("=========================")
    listExt(res)
}

// list all Base for files in p
func listBase(p path) {
    if glob, err := p.Glob("*"); err != nil {
        log.Fatal(err)
    } else {
        for _, match := range glob {
            fmt.Println(match.Base())
        }
    }
}

// list all extensions for files in p
func listExt(p path) {
    if glob, err := p.Glob("*"); err != nil {
        log.Fatal(err)
    } else {
        for _, match := range glob {
            fmt.Println(match.Ext())
        }
    }
}

Output

example
example/myfile.txt
/home/jonchun/example_module/example
=========================
1.log
2.log
example.txt
=========================
.log
.log
.txt

See GoDoc for documentation, but it should be pretty self-explanatory.

TODO

  • Update examples for all the methods and have 1-to-1 coverage of the official examples/docs.