擅长:python、mysql、java
<p>在适当位置修改<code>dirs</code><em>将删除<code>os.walk</code>访问的(后续)文件和目录:</p>
<pre><code># exclude = set([...])
for root, dirs, files in os.walk(top, topdown=True):
dirs[:] = [d for d in dirs if d not in exclude]
</code></pre>
<hr/>
<p>从帮助(os.walk):</p>
<blockquote>
<p>When topdown is true, the caller can modify the dirnames list in-place
(e.g., via del or slice assignment), and walk will only recurse into
the subdirectories whose names remain in dirnames; this can be used to
prune the search...</p>
</blockquote>