Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Return Dirent's internal base directory via Dir() (and possibly more...) #74

Open
GwynethLlewelyn opened this issue Aug 26, 2023 · 1 comment

Comments

@GwynethLlewelyn
Copy link

GwynethLlewelyn commented Aug 26, 2023

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 (de Dirent) Dir() string { return de.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 :)

@GwynethLlewelyn
Copy link
Author

... 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant