Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io/ioutil: ReadDir fails to list directory for bare drive path #45514

Closed
adminck opened this issue Apr 12, 2021 · 6 comments
Closed

io/ioutil: ReadDir fails to list directory for bare drive path #45514

adminck opened this issue Apr 12, 2021 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@adminck
Copy link

adminck commented Apr 12, 2021

What version of Go are you using (go version)?

$ go version
go version go1.14.2 windows/amd64

Does this issue reproduce with the latest release?

YES

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOENV=C:\Users\Administrator\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=F:\go\GOPATH
set GOPRIVATE=
set GOPROXY=https://goproxy.io
set GOROOT=F:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=F:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADM
INI~1\AppData\Local\Temp\go-build731386154=/tmp/go-build -gno-record-gcc-switche
s

What did you do?

Create new program from scratch, write,build:

func main() {
	rd, _ := ioutil.ReadDir("f:")
	for _, fi := range rd {
		fmt.Println(fi.Name())
	}
}

File running path “F:\test\”

What did you expect to see?

Output f root directory file list

What did you see instead?

Output “F:\test\” directory file list

@adminck
Copy link
Author

adminck commented Apr 12, 2021

For Windows API FindFirstFile, if the parameter is the program running drive letter and there is no "\" after the drive letter, the list of files in the program running directory will be output. recommended "os\file_windows.go " Adding "\" in 115 line splicing path

@mknyszek mknyszek changed the title ioutil.ReadDir get filelist error ioutil: ReadDir fails to list directory for bare drive path Apr 12, 2021
@mknyszek mknyszek added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows labels Apr 12, 2021
@mknyszek mknyszek added this to the Backlog milestone Apr 12, 2021
@mknyszek mknyszek changed the title ioutil: ReadDir fails to list directory for bare drive path io/ioutil: ReadDir fails to list directory for bare drive path Apr 12, 2021
@mknyszek
Copy link
Contributor

CC @griesemer @ianlancetaylor @bradfitz via https://dev.golang.org/owners. We don't actually seem to have granular owners for io subpackages. Also @rsc who deprecated all of ioutil.

@adminck have you tried using os.ReadDir instead? The documentation states that that's the better option (and more correct option) these days.

@mknyszek
Copy link
Contributor

Of course, if this is broken in some new way, we should fix it.

@slrz
Copy link

slrz commented Apr 12, 2021

For Windows API FindFirstFile, if the parameter is the program running drive letter and there is no "" after the drive letter, the list of files in the program running directory will be output.

Isn't this the intended behaviour? Windows keeps a separate working directory per drive letter and I presume this is how to access it?

Why do you expect a readdir for a non-rooted path to return the root directory's contents?

@ghost
Copy link

ghost commented Apr 14, 2021

Works as intended. Run cd c:\Users and then dir c: in the cmd shell. It won't list the contents of the root directory.

@seankhliao
Copy link
Member

Closing as working as intended

@golang golang locked and limited conversation to collaborators Apr 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants