Created
May 25, 2022 10:35
-
-
Save VTRyo/0128431d8e6b25ff1ff9298cda93a077 to your computer and use it in GitHub Desktop.
List the file paths in the directory
This file contains 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
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")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
ref: https://qiita.com/tanksuzuki/items/7866768c36e13f09eedb