Created
March 16, 2021 18:43
-
-
Save clarkmcc/1fdab4472283bb68464d066d6b4169bc to your computer and use it in GitHub Desktop.
Get all filenames inside an Golang embedded filesystem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Good job guys.
Modified your solution to suit my needs.
Maybe it will be just as useful for someone.