Skip to content

Instantly share code, notes, and snippets.

@radeksimko
Last active August 2, 2022 15:01
Show Gist options
  • Save radeksimko/8c4daf62377e64ee2bc2f83afd1361e9 to your computer and use it in GitHub Desktop.
Save radeksimko/8c4daf62377e64ee2bc2f83afd1361e9 to your computer and use it in GitHub Desktop.
Windows paths test
package main
import (
"io/fs"
"log"
"os"
"path"
)
func main() {
filesystem := os.DirFS("C:\\")
// 1st case
dirPath := path.Join("C:\\FooBar", "baz")
entries, err := fs.ReadDir(filesystem, dirPath)
if err != nil {
log.Fatal(err)
}
log.Printf("1: entries: %d", len(entries))
for _, entry := range entries {
log.Printf("entry: %q\n", entry.Name())
}
// 2nd case
filePath := path.Join("C:\\FooBar\\baz", "blah.txt")
f, err := fs.ReadFile(filesystem, filePath)
if err != nil {
log.Fatal(err)
}
log.Printf("2: file content: %q", string(f))
// 3rd case
f, err = fs.ReadFile(os.DirFS("C:\\FooBar\\baz"), "blah.txt")
if err != nil {
log.Fatal(err)
}
log.Printf("3: file content: %q", string(f))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment