Find all files on any drives

hi guys…
i want to find the files on any system drives…
what is my code problem ?
Error : cannot use root (type []string) as type string in argument to filepath.Walk

line : err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {

var files []string
  SystemDirvesList := []string{}
  for _, drives := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" {
    _, err := os.Open(string(drives) + ":\\")
    if err == nil {
      SystemDirvesList = append(SystemDirvesList, string(drives))


  root := SystemDirvesList
  err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
    files = append(files, path)
    return nil
  if err != nil {
  for _, file := range files {
1 Like

The error message tells it already. root needs to be a single string, not a slice thereof.

Looping over the elements in root might help?

how i can slove this problem?

Have you tried a loop, as I suggested earlier?

i writing any programs with python. i tested this loop but not working ( like python )…
maybe this code need type casting.

for _,TestVariable := range DriversList{
bla bla bla

Since there is no DriversList in the code you have originally shown to us, I can’t say what you have done.

Also I have no clue what the body of the loop should be, as there is no bla bla bla in the original code.

Please show the code that is not working and show the error it produces.

Also please use markdown to mark your codeblocks like this:

// your code here

Screen of Errors And Code :

Sorry, but I can not copy and paste from screenshots.

but roughly:

for _, r := range root {
  err := filepath.Walk(r, …)
  // error handling and other code

Using a loop is the easiest way to get a T from a []T.

PS: None of the screenshots shows what you wanted to say with your Find all files on any drives post

i tested this way bot not working.please look this screen :

The next screenshot will be pretended to not exist. Most of the time I’m browsing the forum via a mobile and screenshots are hard to read here. Properly marked code blocks work much better and do not strain my bandwith quota.

From what I can read out of the documentation of filepath.Walk, the type of the info argument needs to be os.FileInfo, perhaps you missed to qualify.

Anyway, the function you try to pass into filepath.Walk seems to be totally off… The root in the argument list seems to be missplaced.

1 Like

Thank you bro…

So does it work for you now?

I’m unable to test my theories here, as I use operating systems without drive letters.

no not working for me…
my script have problem.

What kind of problems? Just try to explain your problem as exact as you are able to, and provide as much context as other might need to help you.

bro this is my error :

Error : cannot use root (type []string) as type string in argument to filepath.Walk
and i dont know how i can slove this.

Which I have told you how to fix, use the damn loop and fix the errors that occur then. One by one.

hey man i tested any ideas but i can’t slove this…
help me if you can

I did as good as I can. So after you fixed the two errors in the func literal you wanted to pass to filepath.Walk waht did happen next?

please go to the this link :