find all files matching exact name with and without an extension
<p>I'm using glob to scan a specified directory to find all files matching the specified name, but I can't seem to get it to work with files with no extension without finding files matching the name and then some...</p>

<p>For example, here's some files:<br>
- file<br>
- file2<br>
- file.dat</p>

<p>The resulting list should be:<br>
<code>[ 'file', 'file.dat' ]</code></p>

<p>How can I get glob to work as expected??</p>

<p>Shortly after posting this question, I thought of the answer, but gave up the phone before I could post it...</p>

<p>So instead of relying on glob to find the royal all files, have it only look for files with extensions.</p>

<p>Here's how to validate if glob is even needed:</p>

<pre><code>path = 'subdirectory/filename' # no extension

files = [ path ] # for consistancy
if not os.path.exists( path ):
    files = glob('%s.*'%path)
    if not files:
        raise IOError("no files found")

for f in files:
    # do whatever
</code></pre>

<p>This should work with most names, including weirdly formatted names.</p>

python glob