Skip to content

Instantly share code, notes, and snippets.

@mlbright
Created January 17, 2018 16:40
Show Gist options
  • Select an option

  • Save mlbright/7d65a5bbd3b29a6a2886da8f49d0e986 to your computer and use it in GitHub Desktop.

Select an option

Save mlbright/7d65a5bbd3b29a6a2886da8f49d0e986 to your computer and use it in GitHub Desktop.

Revisions

  1. mlbright created this gist Jan 17, 2018.
    24 changes: 24 additions & 0 deletions filepath-examples.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    package main

    import (
    "fmt"
    "path/filepath"
    )

    func main() {
    paths := []string{
    "/home/arnie/amelia.jpg",
    "/mnt/photos/",
    "/mnt/photos",
    "mnt/photos",
    "rabbit.jpg",
    "/usr/local//go",
    ".",
    "/",
    }
    fmt.Println("On Unix:")
    for _, p := range paths {
    dir, file := filepath.Split(p)
    fmt.Printf("input: %q\n\tdir: %q\n\tfilepath.Dir: %q\n\tfile: %q\n", p, dir, filepath.Dir(p), file)
    }
    }