Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
91672686
Commit
91672686
authored
Feb 17, 2012
by
Mike Rosset
Committed by
Rob Pike
Feb 17, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc: provide example filepath.Walk for go1
R=golang-dev, r, r CC=golang-dev
https://golang.org/cl/5674067
parent
785ee50c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
8 deletions
+39
-8
go1.html
doc/go1.html
+16
-4
go1.tmpl
doc/go1.tmpl
+2
-4
go1.go
doc/progs/go1.go
+21
-0
No files found.
doc/go1.html
View file @
91672686
...
@@ -1540,12 +1540,24 @@ instead of a <code>Visitor</code> interface value.
...
@@ -1540,12 +1540,24 @@ instead of a <code>Visitor</code> interface value.
The
<code>
WalkFunc
</code>
function will be called even for files or directories that could not be opened;
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.
in such cases the error argument will describe the failure.
If a directory's contents are to be skipped,
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>
<p>
<pre>
<!--{{code "progs/go1.go" `/STARTWALK/` `/ENDWALK/`}}
<font
color=
"red"
>
TODO: add an example?
</font>
-->
markFn := func(path string, info os.FileInfo, err error) error {
</p>
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>
<p>
<em>
Updating
</em>
:
<em>
Updating
</em>
:
...
...
doc/go1.tmpl
View file @
91672686
...
@@ -1439,12 +1439,10 @@ instead of a <code>Visitor</code> interface value.
...
@@ -1439,12 +1439,10 @@ instead of a <code>Visitor</code> interface value.
The <code>WalkFunc</code> function will be called even for files or directories that could not be opened;
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.
in such cases the error argument will describe the failure.
If a directory'
s
contents
are
to
be
skipped
,
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
>
<
p
>
{{
code
"progs/go1.go"
`/
STARTWALK
/`
`/
ENDWALK
/`}}
<
font
color
=
"red"
>
TODO
:
add
an
example
?</
font
>
</
p
>
<
p
>
<
p
>
<
em
>
Updating
</
em
>:
<
em
>
Updating
</
em
>:
...
...
doc/progs/go1.go
View file @
91672686
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
"fmt"
"fmt"
"log"
"log"
"os"
"os"
"path/filepath"
"testing"
"testing"
"time"
"time"
"unicode"
"unicode"
...
@@ -28,6 +29,7 @@ func main() {
...
@@ -28,6 +29,7 @@ func main() {
runeType
()
runeType
()
errorExample
()
errorExample
()
timePackage
()
timePackage
()
walkExample
()
osIsExist
()
osIsExist
()
}
}
...
@@ -183,6 +185,25 @@ func timePackage() {
...
@@ -183,6 +185,25 @@ func timePackage() {
sleepUntil
(
time
.
Now
()
.
Add
(
123
*
time
.
Millisecond
))
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
)
{
func
initializationFunction
(
c
chan
int
)
{
c
<-
1
c
<-
1
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment