Python search for single filename recursively in directory tree. Return false if not found
<p>Using Python, I would like to search a directory tree recursively for a specific file name.</p>

<p>**If found, print nothing.</p>

<p>**If not found print a message stating it was not found.</p>

<p>===== here is what I have so far, no errors, but no message when file not found either=====</p>

<pre><code>import os
rootDir = 'G:\\some_top_directory\\'
file_name = 'fileOFinterest.txt'
def find_file(file_name,rootDir):
    for dirpath, dirnames, filenames in os.walk(rootDir):
        if file_name in filenames:
            print 'found'
</code></pre>

<p>If you are using Python3.5+ you can use <code>**</code> with the <code>recursive</code> flag:</p>

<pre><code>import glob
rootDir = 'G:\\some_top_directory\\'
file_name = 'fileOFinterest.txt'
found_files = glob.glob("{}**\\{}".format(rootDir, file_name), recursive=True)
if not found_files:
    # do whatever you need
    pass
else:
    print('found')
</code></pre>

python recursion filenames os.walk