diff --git a/cmd/os-readdir_windows.go b/cmd/os-readdir_windows.go index 191ad6a24..74e98a734 100644 --- a/cmd/os-readdir_windows.go +++ b/cmd/os-readdir_windows.go @@ -19,6 +19,7 @@ package cmd import ( + "io" "os" "syscall" ) @@ -79,10 +80,16 @@ func readDirN(dirPath string, count int) (entries []string, err error) { } defer f.Close() + // Check if file or dir. This is the quickest way. + _, err = f.Seek(0, io.SeekStart) + if err == nil { + return nil, errFileNotFound + } data := &syscall.Win32finddata{} + handle := syscall.Handle(f.Fd()) for count != 0 { - e := syscall.FindNextFile(syscall.Handle(f.Fd()), data) + e := syscall.FindNextFile(handle, data) if e != nil { if e == syscall.ERROR_NO_MORE_FILES { break