Find all files on any drives

Using the loop seems to work, the program runs then on the play ground without any errors or any output.

https://play.golang.org/p/La8WNxuLFiG

your code just returned drives list…
i can give system drives list…
i want find any files on the drives…

As I said already, I’m not using windows, nor would I have access to one (where I could install go).

Also I have to say, that https://play.golang.org/p/gmk3lhGU070 seems to work, as it prints a list of files on the system.

So it is probably some windows thing. Have you tried inspecting err in the WalkerFn or the path or anything?

yes bro… but not working!

your code is true… But I want to show me all drives files… you entered directly path.
this is my idea :
1- find windows drives list
2- find files on the drives
3- show me files path

If you use my code, but provide "C:\\" directly, does it print you something? If yes, then you are probably detecting your drives wrong.

https://play.golang.org/p/gmk3lhGU070
this script working Properly … but i want this script using windows drives.

Check this

func getdrives() (r []string){
for _, drive := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ"{
    _, err := os.Open(string(drive)+":\\")
    if err == nil {
        r = append(r, string(drive))
    }
}
return

}

Does that script run on your computer when you hardcode a single drive you know to exist?

Its not the first time I’m asking exactly this…

yes …

i can get drives list. i need find any files on founded drives

Okay, you know it works for a single drive letter, and you said you have a way to get the drive letters, now just loop over the drive letters with the body in my example, only the hardcoded drive letter swapped by the looping variable. Does that work or do you see any error?

If it does neither work, nor it prints any error, please show the code you used.

with my script i just can give drives list
check below link please :
https://play.golang.org/p/ddxHzaBkWjv

Again.

You said, can get a slice of available drives.
You said you can get the list of files printed for a single hard coded drive.

Whats the hard part to loop over the list of drives and just print the list for each of those?

Or instead of printing, append them to a slice which you initialise empty before the loop?

I sloved this problem. ty guys…

https://play.golang.org/p/ZARTZJvo9y2

Nice you managed it!

I did some cleanup which massively removed indentation.

  1. Happy path is left aligned, instead of doing something if err == nil, you skip it if err != nil.
  2. extracted the walker function.

I also built the “root” once, instead of doing two string concatenations, which even do different things.

2 Likes

And now I realize, that I even forgot to link to my changes on the playground :wink:

I’ll redo and link when I have a computer available.

1 Like

As promised, my version: https://play.golang.org/p/CnEI3X9CyzJ

3 Likes

Your patience and persistence is admirable.

5 Likes

Yes, what @sdmcallister said. You’re amazing @NobbZ. :metal: