I'm using the reasonably new FileSystem style to do the usual directory walk
processing every file in the usual recursive manner.
I can't figure out how to get the directory data (the path up to the last /)
even though I can see it in the output.
I am missing the proper name of the getter, or perhaps a cast/type assertion
Playground:
https://go.dev/play/p/Fde-rAA5YZIThe key code is
fsys := os.DirFS(".")
fs.WalkDir(fsys, ".", func(p string, d fs.DirEntry, err error) error {
fmt.Printf("%s struct: %T %v\n", p, d, d)
which prints "'p" the current file name and extension
the type of the fs.DirEntry and then the fsDirEntry structure
Something like this:
csvtsd/csvtsd.go struct: *os.unixDirent &{../csvtsd csvtsd.go 0 <nil>}
csvtsd/csvtsd_test.go struct: *os.unixDirent &{../csvtsd csvtsd_test.go 0 <nil>}
csvtsd/go.mod struct: *os.unixDirent &{../csvtsd go.mod 0 <nil>}
You can see that the "p" is typically the path and filename
csvtsd/csvtsd.go
the type is a *os.unixDirent
and there are four fields in the Dirent, the path (up to the last /)
the filename and extension, and two other fields.
Thanks