Skip to content

Instantly share code, notes, and snippets.

@mlbright
Created January 17, 2018 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlbright/7d65a5bbd3b29a6a2886da8f49d0e986 to your computer and use it in GitHub Desktop.
Save mlbright/7d65a5bbd3b29a6a2886da8f49d0e986 to your computer and use it in GitHub Desktop.
Compare golang's filepath.Split and filepath.Dir
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)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment