Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A quick test to read the OneDrive Folder in the current user's home directory. (Based off of: http://www.golangprograms.com/how-to-read-names-of-all-files-and-folders-in-current-directory.html)
package main
import (
"log"
"os"
"fmt"
"os/user"
)
func readCurrentDir() {
usr, err := user.Current()
if err != nil {
log.Fatal( err )
}
fmt.Println("User's Home Directory: " + usr.HomeDir + "\n")
file, err := os.Open(usr.HomeDir + "\\OneDrive")
if err != nil {
log.Fatalf("failed opening directory: %s", err)
}
defer file.Close()
list,_ := file.Readdirnames(0) // 0 to read all files and folders
for _, name := range list {
fmt.Println(name)
}
}
func main() {
readCurrentDir()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.