The <code>WalkFunc</code> function will be called even for files or directories that could not be opened;
in such cases the error argument will describe the failure.
If a directory's contents are to be skipped,
-the function should return the value <code>SkipDir</code>.
+the function should return the value <a href="/pkg/path/filepath/#variables"><code>filepath.SkipDir</code></a>
</p>
-<p>
-<font color="red">TODO: add an example?</font>
-</p>
+<pre><!--{{code "progs/go1.go" `/STARTWALK/` `/ENDWALK/`}}
+--> markFn := func(path string, info os.FileInfo, err error) error {
+ if path == "pictures" { // Will skip walking of directory pictures and its contents.
+ return filepath.SkipDir
+ }
+ if err != nil {
+ return err
+ }
+ log.Println(path)
+ return nil
+ }
+ err := filepath.Walk(".", markFn)
+ if err != nil {
+ log.Fatal(err)
+ }</pre>
<p>
<em>Updating</em>:
The <code>WalkFunc</code> function will be called even for files or directories that could not be opened;
in such cases the error argument will describe the failure.
If a directory's contents are to be skipped,
-the function should return the value <code>SkipDir</code>.
+the function should return the value <a href="/pkg/path/filepath/#variables"><code>filepath.SkipDir</code></a>
</p>
-<p>
-<font color="red">TODO: add an example?</font>
-</p>
+{{code "progs/go1.go" `/STARTWALK/` `/ENDWALK/`}}
<p>
<em>Updating</em>:
"fmt"
"log"
"os"
+ "path/filepath"
"testing"
"time"
"unicode"
runeType()
errorExample()
timePackage()
+ walkExample()
osIsExist()
}
sleepUntil(time.Now().Add(123 * time.Millisecond))
}
+func walkExample() {
+ // STARTWALK OMIT
+ markFn := func(path string, info os.FileInfo, err error) error {
+ if path == "pictures" { // Will skip walking of directory pictures and its contents.
+ return filepath.SkipDir
+ }
+ if err != nil {
+ return err
+ }
+ log.Println(path)
+ return nil
+ }
+ err := filepath.Walk(".", markFn)
+ if err != nil {
+ log.Fatal(err)
+ }
+ // ENDWALK OMIT
+}
+
func initializationFunction(c chan int) {
c <- 1
}