Forked from francoishill/loop_files_folders_recursively.go
Created
September 3, 2016 15:53
-
-
Save MaraScott/2841bc8c7015768856ff250eb2e03b5c to your computer and use it in GitHub Desktop.
Loop through files and folders recursively in golang
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" | |
"os" | |
"path/filepath" | |
) | |
func main() ([]string, error) { | |
searchDir := "c:/path/to/dir" | |
fileList := []string{} | |
err := filepath.Walk(searchDir, func(path string, f os.FileInfo, err error) error { | |
fileList = append(fileList, path) | |
return nil | |
}) | |
for _, file := range fileList { | |
fmt.Println(file) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment