Hint #1: Note that fs.DirEntry.Name() only contains the final component of
the path: https://golang.org/pkg/io/fs/#DirEntry.

Hint #2: Note that fs.WalkDirFunc()'s first argument is the full path to
the directory entry: https://golang.org/pkg/io/fs/#WalkDirFunc. See the
example for the older fs.Walk() function:
https://golang.org/pkg/path/filepath/#example_Walk.

On Sun, May 9, 2021 at 7:53 PM Adam C <a...@monkeez.org> wrote:

>
> I'm trying to come up with a fairly small script to find a directory and
> then list the contents of a given directory name.
>
> The filestructure is thus:
> /root/1/1
> /root/1/2
> /root/1/BigZoom
> /root/1/BigZoom/1
> /root/2/1
> /root/2/2
> /root/2/BigZoom
> /root/2/BigZoom/1
>
> I want to find any file in a directory named BigZoom. I'm new to Go, but
> thought I'd give it a go.
>
> I use filepath.WalkDir in this code https://play.golang.org/p/ivqA7o2nCCs
> - it seems that my problem is passing a fileinfo.Name to ReadDir. What
> should go on line 25 for the ReadDir call? I thought I could pass in a
> string, but I'm getting:
>
> panic: open BigZoom: no such file or directory
>
> Any help would be much appreciated - thanks in advance.
>
> Adam
>
> --
> 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/9ec35241-8fa6-49bd-ad07-56b57cc8cd3an%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/9ec35241-8fa6-49bd-ad07-56b57cc8cd3an%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
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/CABx2%3DD8n_GjJYqXimWSXaZWPz6NXkSvyZn6%3DwqYEpTEwQhyDcg%40mail.gmail.com.

Reply via email to