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)
}
stat, err := os.Stat(usr.HomeDir + "\\OneDrive")
if err != nil {
log.Fatalf("failed stating directory: %s", err)
}
lstat, err := os.LStat(usr.HomeDir + "\\OneDrive")
if err != nil {
log.Fatalf("failed lstating 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()
}
@clee231

This comment has been minimized.

Copy link

clee231 commented Nov 25, 2017

Following from https://forum.syncthing.net/t/folder-path-missing-even-the-path-exists-onedrive-win10-fall-creators-update/10913/11?u=geeksquads

I can't seem to build this? It complains that os.Lstat is undefined. Sorry if I'm doing this incorrectly, I'm not all too familiar with go-lang.


Windows 10 (Fall Creator's Update) Version 1709
OS Build: 16299.19

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.