Skip to content

Instantly share code, notes, and snippets.

@ajeya
Forked from clarkmcc/main.go
Created October 31, 2022 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajeya/37adf0470eece2e2a93e2089f4e19080 to your computer and use it in GitHub Desktop.
Save ajeya/37adf0470eece2e2a93e2089f4e19080 to your computer and use it in GitHub Desktop.
Get all filenames inside an Golang embedded filesystem.
func getAllFilenames(fs *embed.FS, path string) (out []string, err error) {
if len(path) == 0 {
path = "."
}
entries, err := fs.ReadDir(path)
if err != nil {
return nil, err
}
for _, entry := range entries {
fp := filepath.Join(path, entry.Name())
if entry.IsDir() {
res, err := getAllFilenames(fs, fp)
if err != nil {
return nil, err
}
out = append(out, res...)
continue
}
out = append(out, fp)
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment