Skip to content

io/ioutil: ReadDir: no error if dirname is a file #9789

@larsbutler

Description

@larsbutler

Hi, I noticed that if you run ioutil.ReadDir("/some/file.txt"), it succeeds and returns an empty array of os.FileInfo and no error. I would expect an error, since the input is a file, not a dir.

See

func ReadDir(dirname string) ([]os.FileInfo, error) {
.

Equivalent operations in the stdlib of, for example, Python are os.listdir, and this raises an error if you pass in a file instead of a directory.

Is this a bug, or is this the intended behavior? If the latter, why?

If it's a bug I'll be happy to submit a patch.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions