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 {
panic(err)
}
for _, file := range files {
fmt.Println(file)
}```
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.