-
-
Save ajeya/37adf0470eece2e2a93e2089f4e19080 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