Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d71ca41

Browse files
committed
Remove os.path.walk
1 parent 699adb9 commit d71ca41

6 files changed

Lines changed: 7 additions & 128 deletions

File tree

Doc/library/os.path.rst

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -261,30 +261,6 @@ write files see :func:`open`, and for accessing the filesystem see the
261261
*unc* will always be the empty string. Availability: Windows.
262262

263263

264-
.. function:: walk(path, visit, arg)
265-
266-
Calls the function *visit* with arguments ``(arg, dirname, names)`` for each
267-
directory in the directory tree rooted at *path* (including *path* itself, if it
268-
is a directory). The argument *dirname* specifies the visited directory, the
269-
argument *names* lists the files in the directory (gotten from
270-
``os.listdir(dirname)``). The *visit* function may modify *names* to influence
271-
the set of directories visited below *dirname*, e.g. to avoid visiting certain
272-
parts of the tree. (The object referred to by *names* must be modified in
273-
place, using :keyword:`del` or slice assignment.)
274-
275-
.. note::
276-
277-
Symbolic links to directories are not treated as subdirectories, and that
278-
:func:`walk` therefore will not visit them. To visit linked directories you must
279-
identify them with ``os.path.islink(file)`` and ``os.path.isdir(file)``, and
280-
invoke :func:`walk` as necessary.
281-
282-
.. note::
283-
284-
The newer :func:`os.walk` :term:`generator` supplies similar functionality
285-
and can be easier to use.
286-
287-
288264
.. data:: supports_unicode_filenames
289265

290266
True if arbitrary Unicode strings can be used as file names (within limitations

Lib/macpath.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
99
"basename","dirname","commonprefix","getsize","getmtime",
1010
"getatime","getctime", "islink","exists","lexists","isdir","isfile",
11-
"walk","expanduser","expandvars","normpath","abspath",
11+
"expanduser","expandvars","normpath","abspath",
1212
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
1313
"devnull","realpath","supports_unicode_filenames"]
1414

@@ -154,33 +154,6 @@ def normpath(s):
154154
s = s[:-1]
155155
return s
156156

157-
158-
def walk(top, func, arg):
159-
"""Directory tree walk with callback function.
160-
161-
For each directory in the directory tree rooted at top (including top
162-
itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
163-
dirname is the name of the directory, and fnames a list of the names of
164-
the files and subdirectories in dirname (excluding '.' and '..'). func
165-
may modify the fnames list in-place (e.g. via del or slice assignment),
166-
and walk will only recurse into the subdirectories whose names remain in
167-
fnames; this can be used to implement a filter, or to impose a specific
168-
order of visiting. No semantics are defined for, or required of, arg,
169-
beyond that arg is always passed to func. It can be used, e.g., to pass
170-
a filename pattern, or a mutable object designed to accumulate
171-
statistics. Passing None for arg is common."""
172-
173-
try:
174-
names = os.listdir(top)
175-
except os.error:
176-
return
177-
func(arg, top, names)
178-
for name in names:
179-
name = join(top, name)
180-
if isdir(name) and not islink(name):
181-
walk(name, func, arg)
182-
183-
184157
def abspath(path):
185158
"""Return an absolute path."""
186159
if not isabs(path):

Lib/ntpath.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
1515
"basename","dirname","commonprefix","getsize","getmtime",
1616
"getatime","getctime", "islink","exists","lexists","isdir","isfile",
17-
"ismount","walk","expanduser","expandvars","normpath","abspath",
17+
"ismount", "expanduser","expandvars","normpath","abspath",
1818
"splitunc","curdir","pardir","sep","pathsep","defpath","altsep",
1919
"extsep","devnull","realpath","supports_unicode_filenames","relpath"]
2020

@@ -226,40 +226,6 @@ def ismount(path):
226226
return len(p) == 1 and p[0] in '/\\'
227227

228228

229-
# Directory tree walk.
230-
# For each directory under top (including top itself, but excluding
231-
# '.' and '..'), func(arg, dirname, filenames) is called, where
232-
# dirname is the name of the directory and filenames is the list
233-
# of files (and subdirectories etc.) in the directory.
234-
# The func may modify the filenames list, to implement a filter,
235-
# or to impose a different order of visiting.
236-
237-
def walk(top, func, arg):
238-
"""Directory tree walk with callback function.
239-
240-
For each directory in the directory tree rooted at top (including top
241-
itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
242-
dirname is the name of the directory, and fnames a list of the names of
243-
the files and subdirectories in dirname (excluding '.' and '..'). func
244-
may modify the fnames list in-place (e.g. via del or slice assignment),
245-
and walk will only recurse into the subdirectories whose names remain in
246-
fnames; this can be used to implement a filter, or to impose a specific
247-
order of visiting. No semantics are defined for, or required of, arg,
248-
beyond that arg is always passed to func. It can be used, e.g., to pass
249-
a filename pattern, or a mutable object designed to accumulate
250-
statistics. Passing None for arg is common."""
251-
252-
try:
253-
names = os.listdir(top)
254-
except os.error:
255-
return
256-
func(arg, top, names)
257-
for name in names:
258-
name = join(top, name)
259-
if isdir(name):
260-
walk(name, func, arg)
261-
262-
263229
# Expand paths beginning with '~' or '~user'.
264230
# '~' means $HOME; '~user' means that user's home directory.
265231
# If the path doesn't begin with '~', or if the user or $HOME is unknown,

Lib/os2emxpath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
import stat
1010
from genericpath import *
1111
from ntpath import (expanduser, expandvars, isabs, islink, splitdrive,
12-
splitext, split, walk)
12+
splitext, split)
1313

1414
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
1515
"basename","dirname","commonprefix","getsize","getmtime",
1616
"getatime","getctime", "islink","exists","lexists","isdir","isfile",
17-
"ismount","walk","expanduser","expandvars","normpath","abspath",
17+
"ismount","expanduser","expandvars","normpath","abspath",
1818
"splitunc","curdir","pardir","sep","pathsep","defpath","altsep",
1919
"extsep","devnull","realpath","supports_unicode_filenames"]
2020

Lib/posixpath.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
1919
"basename","dirname","commonprefix","getsize","getmtime",
2020
"getatime","getctime","islink","exists","lexists","isdir","isfile",
21-
"ismount","walk","expanduser","expandvars","normpath","abspath",
21+
"ismount", "expanduser","expandvars","normpath","abspath",
2222
"samefile","sameopenfile","samestat",
2323
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
2424
"devnull","realpath","supports_unicode_filenames","relpath"]
@@ -193,44 +193,6 @@ def ismount(path):
193193
return False
194194

195195

196-
# Directory tree walk.
197-
# For each directory under top (including top itself, but excluding
198-
# '.' and '..'), func(arg, dirname, filenames) is called, where
199-
# dirname is the name of the directory and filenames is the list
200-
# of files (and subdirectories etc.) in the directory.
201-
# The func may modify the filenames list, to implement a filter,
202-
# or to impose a different order of visiting.
203-
204-
def walk(top, func, arg):
205-
"""Directory tree walk with callback function.
206-
207-
For each directory in the directory tree rooted at top (including top
208-
itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
209-
dirname is the name of the directory, and fnames a list of the names of
210-
the files and subdirectories in dirname (excluding '.' and '..'). func
211-
may modify the fnames list in-place (e.g. via del or slice assignment),
212-
and walk will only recurse into the subdirectories whose names remain in
213-
fnames; this can be used to implement a filter, or to impose a specific
214-
order of visiting. No semantics are defined for, or required of, arg,
215-
beyond that arg is always passed to func. It can be used, e.g., to pass
216-
a filename pattern, or a mutable object designed to accumulate
217-
statistics. Passing None for arg is common."""
218-
219-
try:
220-
names = os.listdir(top)
221-
except os.error:
222-
return
223-
func(arg, top, names)
224-
for name in names:
225-
name = join(top, name)
226-
try:
227-
st = os.lstat(name)
228-
except os.error:
229-
continue
230-
if stat.S_ISDIR(st.st_mode):
231-
walk(name, func, arg)
232-
233-
234196
# Expand paths beginning with '~' or '~user'.
235197
# '~' means $HOME; '~user' means that user's home directory.
236198
# If the path doesn't begin with '~', or if the user or $HOME is unknown,

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Library
2424

2525
- The imputil module has been removed.
2626

27+
- os.path.walk has been removed in favor of os.walk
28+
2729
Build
2830
-----
2931

0 commit comments

Comments
 (0)