Created
April 25, 2021 21:24
-
-
Save Ramko9999/d49a3f944a6530c099367395f9dace68 to your computer and use it in GitHub Desktop.
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
import ( | |
"fmt" | |
"io/fs" | |
"path/filepath" | |
) | |
// example of counting all files in a root directory | |
func countFiles() int { | |
count := 0; | |
filepath.WalkDir(".", func(path string, file fs.DirEntry, err error) error { | |
if err != nil { | |
return err | |
} | |
if !file.IsDir() { | |
fmt.Println(path); | |
count++; | |
} | |
return nil; | |
}); | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment