Source file
src/os/dir_windows.go
1
2
3
4
5 package os
6
7 import (
8 "io"
9 "runtime"
10 "syscall"
11 )
12
13 func (file *File) readdir(n int, mode readdirMode) (names []string, dirents []DirEntry, infos []FileInfo, err error) {
14 if !file.isdir() {
15 return nil, nil, nil, &PathError{Op: "readdir", Path: file.name, Err: syscall.ENOTDIR}
16 }
17 wantAll := n <= 0
18 if wantAll {
19 n = -1
20 }
21 d := &file.dirinfo.data
22 for n != 0 && !file.dirinfo.isempty {
23 if file.dirinfo.needdata {
24 e := file.pfd.FindNextFile(d)
25 runtime.KeepAlive(file)
26 if e != nil {
27 if e == syscall.ERROR_NO_MORE_FILES {
28 break
29 } else {
30 err = &PathError{Op: "FindNextFile", Path: file.name, Err: e}
31 return
32 }
33 }
34 }
35 file.dirinfo.needdata = true
36 name := syscall.UTF16ToString(d.FileName[0:])
37 if name == "." || name == ".." {
38 continue
39 }
40 if mode == readdirName {
41 names = append(names, name)
42 } else {
43 f := newFileStatFromWin32finddata(d)
44 f.name = name
45 f.path = file.dirinfo.path
46 f.appendNameToPath = true
47 if mode == readdirDirEntry {
48 dirents = append(dirents, dirEntry{f})
49 } else {
50 infos = append(infos, f)
51 }
52 }
53 n--
54 }
55 if !wantAll && len(names)+len(dirents)+len(infos) == 0 {
56 return nil, nil, nil, io.EOF
57 }
58 return names, dirents, infos, nil
59 }
60
61 type dirEntry struct {
62 fs *fileStat
63 }
64
65 func (de dirEntry) Name() string { return de.fs.Name() }
66 func (de dirEntry) IsDir() bool { return de.fs.IsDir() }
67 func (de dirEntry) Type() FileMode { return de.fs.Mode().Type() }
68 func (de dirEntry) Info() (FileInfo, error) { return de.fs, nil }
69
View as plain text