擅长:python、mysql、java
<p>这可能对您有用:</p>
<pre><code>import os
File = 'dwnld.py'
for root, dirs, files in os.walk('/Users/BobbySpanks/'):
if File in files:
print ("File exists")
</code></pre>
<hr/>
<blockquote>
<p><code>os.walk(top, topdown=True, onerror=None, followlinks=False)</code> </p>
<p>Generate
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 top
(including top itself), it yields a 3-tuple (dirpath, dirnames,
filenames).
<sub><a href="https://docs.python.org/3/library/os.html" rel="nofollow noreferrer">Source</a></sub></p>
</blockquote>