Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4e09f676
Commit
4e09f676
authored
Apr 28, 2003
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
walk() docs: Worked "walking" into the description and the text. Added
a brief example where bottom-up walking is essential.
parent
de4b20ec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
Doc/lib/libos.tex
Doc/lib/libos.tex
+18
-1
No files found.
Doc/lib/libos.tex
View file @
4e09f676
...
...
@@ -1053,7 +1053,8 @@ Availability: Macintosh, \UNIX, Windows.
\begin{funcdesc}
{
walk
}{
top
\optional
{
, topdown
\code
{
=True
}}}
\index
{
directory!walking
}
\index
{
directory!traversal
}
\function
{
walk()
}
generates the file names in a directory tree.
\function
{
walk()
}
generates the file names in a directory tree, by
walking the tree either top down or bottom up.
For each directory in the tree rooted at directory
\var
{
top
}
(including
\var
{
top
}
itself), it yields a 3-tuple
\code
{
(
\var
{
dirpath
}
,
\var
{
dirnames
}
,
\var
{
filenames
}
)
}
.
...
...
@@ -1112,6 +1113,22 @@ for root, dirs, files in os.walk('python/Lib/email'):
if 'CVS' in dirs:
dirs.remove('CVS') # don't visit CVS directories
\end{verbatim}
In the next example, walking the tree bottom up is essential:
\function
{
rmdir()
}
doesn't allow deleting a directory before the
directory is empty:
\begin{verbatim}
import os
from os.path import join
# Delete everything reachable from the directory named in 'top'.
for root, dirs, files in os.walk(top, topdown=False):
for name in files:
os.remove(join(root, name))
for name in dirs:
os.rmdir(join(root, name))
\end{verbatim}
\versionadded
{
2.3
}
\end{funcdesc}
...
...
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