Skip to content

Instantly share code, notes, and snippets.

@VTRyo
Created May 25, 2022 10:35
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 VTRyo/0128431d8e6b25ff1ff9298cda93a077 to your computer and use it in GitHub Desktop.
Save VTRyo/0128431d8e6b25ff1ff9298cda93a077 to your computer and use it in GitHub Desktop.
List the file paths in the directory
package main
import (
"fmt"
"io/ioutil"
"path/filepath"
)
func fileList(dir string) []string {
files, err := ioutil.ReadDir(dir)
if err != nil {
panic(err)
}
var paths []string
for _, file := range files {
if file.IsDir() {
paths = append(paths, fileList(filepath.Join(dir, file.Name()))...)
continue
}
paths = append(paths, filepath.Join(dir, file.Name()))
}
return paths
}
func main() {
fmt.Println(fileList("dir/path"))
}
@VTRyo
Copy link
Author

VTRyo commented May 25, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment