Skip to content

Instantly share code, notes, and snippets.

@Ramko9999
Last active April 26, 2021 03:18
Show Gist options
  • Save Ramko9999/bfa8b6f692e794773dfd1b02ee595496 to your computer and use it in GitHub Desktop.
Save Ramko9999/bfa8b6f692e794773dfd1b02ee595496 to your computer and use it in GitHub Desktop.
import (
"fmt"
"log"
"os"
)
/*
Suppose this was the directory structure of test:
- test
- a.txt
- b
- c.txt
getDirectoryContents will print out "a.txt" and "b".
*/
func getDirectoryContents(){
entries, err := os.ReadDir("./test");
if err != nil {
log.Fatal(err);
}
//iterate through the directory entities and print out their name.
for _, entry := range(entries) {
fmt.Println(entry.Name());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment