Now I am using Walk to go through my folder, I want to filter some folder when scan.
err := filepath.Walk("/home", func(path string, f os.FileInfo, err error) error {
...
})
The folder structure is:
home
/ | \
a b c
Can I make some exception list that filepath.Walk not scan folder a
? That is, I do not want any files in folder a
add into my scan result.
From the documentation for WalkFuc
:
If an error is returned, processing stops. The sole exception is that if path is a directory and the function returns the special value SkipDir, the contents of the directory are skipped and processing continues as usual on the next file.
So simply make the function you pass to filepath.Walk
return filepath.SkipDir
when path
is the directory you want skipped.