On Sat, Mar 13, 2021 at 11:52 PM rob <drrob...@fastmail.com> wrote: > Sorry, I did not intend to open a new thread. > > I don't know how to answer you about the actual contents of the directory > of interest. It's my c:\users\rob\Documents directory. > > There are a lot of files there. I'm writing my own version of the dir > command, one that will sort and behave exactly as I want. I decided to > experiment w/ the new library definitions; and discovered that DirEntry is > not a replacement for FileInfo. I thought that was the intent of the Go > team, but I guess did not understand. > It is, for most use-cases that want to list the contents of a file. It works around the fact that on many platforms, you already get *some* info in the readdir call but some info only by following it up with a Stat - returning a FileInfo requires you to do the stat, but most applications only need the things returned already by readdir itself and don't need to follow it up with a separate stat call. The DirEntry design splits up the info returned by readdir (namely the file names and the file mode) from the info returned by stat (the DirEntry.Info method).
I still don't understand why you think that ReadDir/DirEntry did not work for you - as I said, from your code the issue seems to simply be that you call ReadDir on regular files, instead of directories. OTOH, as long as you've find a solution that works for you, I guess that's fine. > In my code I went back to using Lstat, and instead of ioutil.ReadDir, I > now use > > f, err := os.Open(directoryname) > > if err != nil { blah blah blah} > > files, err := f.Readdir(0) > > if err != nil { blah blah blah} > > And this works for me. > > --rob solomon > > > > On 3/11/21 4:00 PM, Axel Wagner wrote: > > I don't understand why you opened a new thread. But FWIW, it would still > be useful to know > a) what the actual contents of the directory are you are globbing > b) which of those file names is then giving you an error > c) and which specific call is returning that error. > > Your message "Unexpected error from os.DirEntry" is confusing, as the only > method of os.DirEntry that could return an error, hardcodes that error to > be nil, as far as I can tell: > > https://github.com/golang/go/blob/b3896fc331c36a539f825f1f656cef3f9cdffd3f/src/os/dir_windows.go#L68 > > In the other thread, I also tried to provide a plausible explanation from > the limited info - it seems strange that you are globbing for *.txt files > and then call ReadDir with those filenames. Have you read that message? > > On Thu, Mar 11, 2021 at 9:31 PM rob <drrob...@fastmail.com> 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. >> >> I'll check, but I'm able to call os.ReadDir on an individual file on >> Ubuntu 20.04. I'll confirm when I get home that I'm getting a FileInfo >> structure returned from this routine >> >> >> >> -- >> rob >> drrob...@fastmail.com >> >> -- >> 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/137cb626-90f1-455e-b0aa-7a6d476e3813%40www.fastmail.com >> . >> > -- 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/CAEkBMfGLk7Th3D9jE-AZB6FtqNgtp4No4HVXDtePC7EX_Y9F-g%40mail.gmail.com.