hi Adam,

you call ReadDir with the file name and not with the full path or the path relative to your current working directory. that means you will try to read the dir with path "BigZoom" two times. the WalkDirFunc passes a path argument that concatenates the path prefix with the dir entry name to form the whole path you can use to read the file.

https://play.golang.org/p/76GxS3TRkha

not locally tested with files, but i hope it shows what i mean.

have fun

On 09.05.21 17:53, Adam C 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 <mailto: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>.

--
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/92748cc5-ef96-cb9b-4eba-096023c440c7%40mb0.org.

Reply via email to