Golang os.File.Readdirnames() function example
package os
Golang os.File.Readdirnames() function usage example
NOTE : Use this function to list all the files in a directory
package main
import (
"fmt"
"os"
)
func main() {
// Open current directory
f, err := os.Open(".")
if err != nil {
panic(err)
}
// Get file names
files, err := f.Readdirnames(0)
if err != nil {
panic(err)
}
// show files
for _, v := range files {
fmt.Println(v)
}
}
Reference :
Advertisement
Something interesting
Tutorials
+4.4k Golang : Valued expressions and functions example
+12.6k Golang : Exit, terminating or aborting a program
+26.4k Golang : Get executable name behind process ID example
+5.8k Golang : Launching your executable inside a console under Linux
+9.5k Golang : Get all countries currencies code in JSON format
+6.1k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+22.4k Golang : How to read JPG(JPEG), GIF and PNG files ?
+6.9k Nginx : Password protect a directory/folder
+10k CodeIgniter : Load different view for mobile devices
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+16k Golang : How to reverse elements order in map ?
+30.6k Golang : Remove characters from string example