/path

A simple library to handle file path input

Primary LanguageGoMIT LicenseMIT

path

Build codecov Go Report Card Go Reference

Overview

A simple library to handle file path input in Go.

Features

  • Hanlde absolute and relative paths
  • Globbing (must be quoted)
  • List files in directories recursivly
  • Optional regex to filter results
  • Cli via flag, see example

Caveats

When passing in globbed patterns via cli you must quote them, if you dont bash will expand them and could result in undesired results. go run cmd/main.go -path "/my/globbed/path/*"

Example

package main

import (
	"flag"
	"fmt"

	"github.com/kmulvey/path"
)

func main() {
	var files path.Entry
	flag.Var(&files, "path", "path to files")
	flag.Parse()

	fmt.Println("user input: ", files.AbsolutePath)
	fmt.Println("number of files found within this path: ", len(files.Children))
}