走文件路径。步行行为

In my code filepath.Walk walks over directories, in the examples all directories are called dir

1.  dir
2.  dir
10.  dir
100.  dir
etc

when walking over the directories it will see

1.  dir
10.  dir
2.  dir

how do i make my own walkFunc so it goes trough directories like this,

1.  dir
2.  dir 
10.  dir 

As mentioned in the docs filepath.Walk traverses entries in lexical order.

If you want to list them in a different order, you can either:

  • do your own traversal using File.ReadDirNames
  • call filepath.Walk, put all the paths into a slice, and sort it as desired.