On Thursday, 11 March 2021 at 20:31:24 UTC rob wrote:

> As the subject line says, this is on windows. 
> I'm getting the file not found error for every file returned by the glob 
> function. 
>
> I guess I misunderstood the purpose of ReadDir, and I really need to call 
> os.Lstat to retrieve the directory information for each individual file 
> that matches the glob pattern on widows 10. 
>
>
The purpose of ReadDir is to list the contents of a *directory*.
 
That is: if stat tells you that the entry is a directory, then you can 
ReadDir to list the files inside that directory.  This is one way to 
traverse a directory tree recursively.

ReadDir doesn't work if the entry is a file, but stat will tell you other 
things you may want to know about the file (such as its size).  If you want 
to read the file contents, then open it and read it as normal.

I'll check, but I'm able to call os.ReadDir on an individual file on Ubuntu 
> 20.04.


That shouldn't work.  For me, with go 1.16 under Ubuntu 18.04:

--------
package main

import (
"fmt"
"os"
)

func main() {
_, err := os.ReadDir("readdir.go")
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
}
--------

Gives:

Error: readdirent readdir.go: not a directory

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c76494ef-2b32-4861-8db8-29760c7fdd28n%40googlegroups.com.

Reply via email to