Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Hands on the filepath Library in Golang

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import "os"
import "fmt"
import "path/filepath"
filepath.Dir("/home/myname/")
/home/myname
filepath.Dir("/home/myname")
/home
filepath.Base("/usr/local/bin")
bin
filepath.Base("/usr/local/bin/abc.txt")
abc.txt
filepath.Base("https://www.legendu.net")
www.legendu.net
filepath.Join("/usr/", "local/bin")
/usr/local/bin

filepath.Glob

Note: The glob package in Python and Rust behave similarly. Both of them find all files and subdirectories for the pattern **/*. However, filepath.Glob behaves different from those 2 packages. filepath.Glob treats **/* as */*.

entries, err := filepath.Glob("./**/*")
entries
[.ipynb_checkpoints/abc-checkpoint.txt .ipynb_checkpoints/hands-on-the-filepath-library-in-golang-checkpoint.ipynb test/.ipynb_checkpoints test/test.txt test/test2]
for _, entry := range entries {
    fmt.Printf("%s\n", entry)
}
.ipynb_checkpoints/abc-checkpoint.txt
.ipynb_checkpoints/hands-on-the-filepath-library-in-golang-checkpoint.ipynb
test/.ipynb_checkpoints
test/test.txt
test/test2