|
18 | 18 | __all__ = ["normcase","isabs","join","splitdrive","split","splitext", |
19 | 19 | "basename","dirname","commonprefix","getsize","getmtime", |
20 | 20 | "getatime","getctime","islink","exists","lexists","isdir","isfile", |
21 | | - "ismount","walk","expanduser","expandvars","normpath","abspath", |
| 21 | + "ismount", "expanduser","expandvars","normpath","abspath", |
22 | 22 | "samefile","sameopenfile","samestat", |
23 | 23 | "curdir","pardir","sep","pathsep","defpath","altsep","extsep", |
24 | 24 | "devnull","realpath","supports_unicode_filenames","relpath"] |
@@ -193,44 +193,6 @@ def ismount(path): |
193 | 193 | return False |
194 | 194 |
|
195 | 195 |
|
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 | | - |
234 | 196 | # Expand paths beginning with '~' or '~user'. |
235 | 197 | # '~' means $HOME; '~user' means that user's home directory. |
236 | 198 | # If the path doesn't begin with '~', or if the user or $HOME is unknown, |
|
0 commit comments