Skip to content

proposal: io/fs: SkipFiles to skip current directory files but not subdirectories #72799

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

Open
pjebs opened this issue Mar 11, 2025 · 3 comments
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Milestone

Comments

@pjebs
Copy link
Contributor

pjebs commented Mar 11, 2025

Proposal Details

Docs: https://pkg.go.dev/io/fs#WalkDirFunc and https://pkg.go.dev/path/filepath#WalkFunc

WalkDirFunc supports the return values SkipDir which skips traversing the current directory and the current directory's sub-directories.

SkipAll basically stops traversing the remaining files and directories.

Proposal:

Implement SkipDirFiles to skip traversing the current files in the current directory BUT NOT sub-directories.

@pjebs pjebs added the Proposal label Mar 11, 2025
@gopherbot gopherbot added this to the Proposal milestone Mar 11, 2025
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Mar 11, 2025
@seankhliao
Copy link
Member

Unlike SkipDir or SkipAll, this doesn't reduce the amount of calls made, WalkDir still needs to read the entire directory to find the nested directory.

it seems too specialized, and more appropriate for the callback to just do early returns as appropriate

@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Mar 11, 2025
@seankhliao seankhliao changed the title proposal: io/fs: WalkDirFunc supports SkipFiles proposal: io/fs: SkipFiles to skip current directory files but not subdirectories Mar 14, 2025
@pjebs
Copy link
Contributor Author

pjebs commented Mar 25, 2025

Note: https://pkg.go.dev/path/filepath#WalkFunc does read the entire list of files/directories in a particular directory.
https://pkg.go.dev/io/fs#WalkDirFunc does not as sean noted.

So for the first package, his argument would not be valid and it would be sensible, beneficial and simple to implement. Secondly, there seems to be a "vibe" to keep the 2 functions similar in functionality. Perhaps it can be implemented in the second package to keep them consistent. If not, then at least implement it in the first package and give another point of difference to choose between the two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Projects
Status: Incoming
Development

No branches or pull requests

4 participants