You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, within the scope of a walk, we can access each Dirent via its associated methods; while it was mostly intended for querying if we're transversing a directory, a symbolic link, etc. there is also the ability to retrieve the base name of the file, namely via the func (de Dirent) Name() string method (the same applies to the mode bits, we get a method for that one as well).
However, internally, the Dirent also stores the directory (i.e. the path minus the base, which, as said, is returned via Name()). It would be awesome if we could get a method for that as well, e.g.
func (deDirent) Dir() string { returnde.path; }
Why is this useful? Well, in my personal use-case, I use godirwalk to quickly retrieve a set of files with a specified list of extensions, which can be arbitrarily deep, and which then gets displayed on a Go template as a structured tree. I'm currently lazily using a struct that merely includes the whole path — which already gets retrieved via the Dirent mechanism.
I suppose that an alternative to that one-liner method is for my own algorithm to track the current directory better :)
The text was updated successfully, but these errors were encountered:
... and now, to make things even more confusing, I've sort of 'extended' the Dirent type (to place the fields I need/want in it). But I've stumbled on another tiny issue, which is separate from this one, so I'll post it on a new thread.
Currently, within the scope of a walk, we can access each
Dirent
via its associated methods; while it was mostly intended for querying if we're transversing a directory, a symbolic link, etc. there is also the ability to retrieve the base name of the file, namely via thefunc (de Dirent) Name() string
method (the same applies to the mode bits, we get a method for that one as well).However, internally, the
Dirent
also stores the directory (i.e. the path minus the base, which, as said, is returned viaName()
). It would be awesome if we could get a method for that as well, e.g.Why is this useful? Well, in my personal use-case, I use
godirwalk
to quickly retrieve a set of files with a specified list of extensions, which can be arbitrarily deep, and which then gets displayed on a Go template as a structured tree. I'm currently lazily using a struct that merely includes the whole path — which already gets retrieved via theDirent
mechanism.I suppose that an alternative to that one-liner method is for my own algorithm to track the current directory better :)
The text was updated successfully, but these errors were encountered: