Hi! On Sat, 14 Jan 2023, Pat Farrell wrote: > On Saturday, January 14, 2023 at 6:52:15 PM UTC-5 raf wrote: >> The function you implement (WalkDirFunc should receive "p" as the path to >> the parent (that seems to be what you want) and "d" as the current >> directory entry. I am not sure why in your example you are showing full >> paths to the file for "p". > > I don't know either. But that is what the code is doing.
The code is doing what the docs for WalkDirFunc[0] say: > The path argument contains the argument to WalkDir as a prefix. That > is, if WalkDir is called with root argument "dir" and finds a file > named "a" in that directory, the walk function will be called with > argument "dir/a". > > The d argument is the fs.DirEntry for the named path. So `p` is always the full path to the current directory entry (i.e. it may be a file, symlink, dir etc etc), and `d` contains a struct that points to the same. As I understand it, the fs-style WalkDir approach does not have a separate argument for the directory the current path is in, nor is it easily gleaned from the `p` or `d` arguments. My recommendation is to use path.Dir[1] to find that information in a portable manner. Here's some example code: https://go.dev/play/p/DOFzOUrVEZ6 HTH, Tobias [0] https://pkg.go.dev/io/fs@go1.19.5#WalkDirFunc [1] https://pkg.go.dev/path#Dir -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/Y8PaTSznSML8wXYa%40skade.schwarzvogel.de.