Golang os.File.Readdir() function example
package os
Golang os.File.Readdir() function usage example
dirname := "." + string(filepath.Separator)
d, err := os.Open(dirname)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer d.Close()
files, err := d.Readdir(-1)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
See full examples at :
https://www.socketloop.com/tutorials/golang-read-directory-content-with-os-open
https://www.socketloop.com/tutorials/golang-copy-directory-including-sub-directories-files
References :
Advertisement
Something interesting
Tutorials
+5.6k PHP : Fix Call to undefined function curl_init() error
+35.3k Golang : Strip slashes from string example
+14.1k Golang : Check if a file exist or not
+12.1k Golang : md5 hash of a string
+5.6k Golang : Shortening import identifier
+34.6k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+11.7k Golang : Find age or leap age from date of birth example
+14.8k Golang : Normalize unicode strings for comparison purpose
+12.6k Golang : flag provided but not defined error
+8k Golang : What fmt.Println() can do and println() cannot do
+19.7k Golang : Archive directory with tar and gzip
+22.1k Golang : Join arrays or slices example